CT55951

Nina's segments Tightest Stretch

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nina runs the cellar at the galleon yard of Masthead. Today the books show a list of segments, and the numbers must be worked out before sundown. Task: All values are positive. Print the length of the shortest contiguous subarray whose sum is at least s, or 0 if none. Input format: First line: n and s. Second line: n positive integers. Output format: Print the minimum length, or 0 if impossible. Constraints: 1 <= n <= 2522; 1 <= a[i] <= 1000000; 1 <= s <= 10^18.

Example 1:

Input: 1581 785520481 298221 93343 829434 691391 806717 560121 804942 381119 915233 479857 865194 197151 848605 170485 345332 785189 306950 583982 127487 267559 826934 122479 388544 315060 831989 255506 216830 671164 632391 913012 322600 383257 987022 6821 327610 956374 900143 145264 888243 990817 805519 613954 139003 319008 392917 620138 222389 837719 74996 113223 167174 135079 938985 448278 566415 722863 656779 164755 794549 127473 487821 62380 413065 835218 591407 540172 736877 692439 887001 7625 346061 816386 404334 173884 281903 348451 888919 218616 77257 256047 812571 870429 228448 628412 350933 548855 96047 506042 7704 292504 770616 416402 550865 800893 17959 325726 483047 214534 482834 298745 192406 32006 414788 974669 841312 350163 825323 519561 806648 416603 733627 657702 208727 32104 8…
Output: 1518

Example 2:

Input: 1149 311891654 979775 192070 118100 98320 915001 135985 18752 260485 355823 579138 999901 468660 812965 852682 802973 351426 998645 818129 232058 400250 536156 239467 482321 708220 637870 80427 212443 56426 199232 406709 641688 321253 715027 741594 634347 497496 711952 739518 775341 356200 285068 305544 459971 301493 239863 63340 469749 155496 302859 538542 816984 289796 999895 143682 857026 788414 959807 262453 521566 488576 717923 62417 661415 99021 985977 134456 91859 433378 874124 521195 412211 992352 701847 199955 790745 434897 120206 135249 288446 903588 820729 54751 306310 558855 937727 307586 1140 55210 199806 200118 308815 413723 554289 627247 502763 342773 590272 29771 831678 485151 552183 358732 303852 930196 732376 991812 359214 846121 678473 401399 608501 696163 280649 764237 …
Output: 596

Example 3:

Input: 2503 1092070309 623307 709903 557623 333442 390901 141167 939053 861688 280735 90562 939646 734323 567122 484581 375600 47004 897124 347956 817552 283466 864009 43879 868827 813403 939665 459529 126362 752647 750141 88685 116272 762186 540196 617965 395155 451670 560619 640183 245832 820850 228427 6334 18831 777223 98132 575659 942965 694905 871176 762560 163500 310912 616031 637537 534008 814267 573728 430685 794554 628971 157887 405685 403170 763973 915788 635417 457722 949359 540370 941037 41466 547368 31784 501800 304551 725983 336610 963262 535912 112109 730541 504653 339201 786960 130623 590021 476893 451187 815588 971404 952023 497860 326754 332409 714039 25414 742594 647802 440377 6645 492410 82561 453130 68132 451591 992348 989129 31202 804601 699959 845001 169758 3391 448462 9499…
Output: 2194

Constraints:

1 <= n <= 2522; 1 <= a[i] <= 1000000; 1 <= s <= 10^18.

Loading...
Test Cases:No test cases
No test cases available.
Nina's segments Tightest Stretch - MEDIUM Coding Problem | CodeTikki