CT48312

Arjun and the Tightest Stretch

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the river town of Willowford opens only for a perfect tally of scrolls. Arjun means to find out. 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 <= 3088; 1 <= a[i] <= 1000000; 1 <= s <= 10^18.

Example 1:

Input: 1720 700615554 102287 599126 703775 20694 502174 734632 835442 643042 18830 119301 427448 828271 765015 398726 770921 878160 944831 822484 54961 59905 236414 335628 953686 497970 576115 393593 122609 146213 235761 924092 583900 636584 578429 996818 939619 7310 354037 219367 99196 452596 234894 760461 699325 515223 496113 586626 604883 16046 884712 666821 938222 214823 716815 603087 164362 325591 724368 247093 544205 463882 467035 56045 40704 288623 454540 347146 788855 581705 623003 290044 185291 799410 398826 244451 597470 906032 847868 378793 601176 134209 342583 940911 258157 554939 369532 205632 772280 700429 294119 730350 115661 724362 165318 797898 138277 204045 52982 182650 379437 239399 662930 767845 290977 719860 391460 124277 281581 595901 349620 652417 954380 987467 63131 393622…
Output: 1402

Example 2:

Input: 3082 154343690 128375 751511 136644 645365 221391 779170 465916 432433 165069 119849 606094 908310 637476 768086 791060 78776 104562 659123 240539 668269 166739 337919 573886 272534 348474 767244 754550 776244 912590 983111 211181 209707 876333 359385 528624 967611 9848 822218 709528 581749 108249 49178 891939 808253 900705 986685 647132 581289 43354 800634 20021 480300 163496 77302 242857 206442 320507 647906 196471 621089 158691 929349 56168 3230 960545 375014 945249 194470 72606 508389 513272 23253 429522 584997 257421 717813 783203 503921 911403 214799 258696 261077 51856 545009 962309 487019 871258 176265 265018 436889 544490 309141 984897 532352 864496 436031 319517 15018 395257 77051 971204 644158 370363 460692 741231 220792 244137 235819 180460 286613 403745 138538 352049 242506 55…
Output: 292

Example 3:

Input: 2789 285474583 965777 435606 767255 789463 102797 261957 372800 10038 366567 363769 874004 882255 957534 183188 68643 125553 691039 602998 699788 108591 161709 450318 927518 841987 630445 262130 74833 830346 333076 494784 831533 811826 780140 491050 311292 111066 789575 409200 254374 672939 67589 729023 59933 595446 770435 379598 651437 834614 403272 42608 7273 952221 666624 447041 322981 393578 261067 138572 860611 711804 707512 90300 55841 178213 223337 379386 702092 53549 898331 630591 728901 24969 982000 26041 305980 54215 417628 218761 517570 459894 331498 36984 289983 926274 491191 528509 704348 119372 104947 356629 265361 761569 674145 987014 792270 757728 23804 542020 957796 165414 913371 868890 726673 419881 472605 328935 632244 478025 399336 520469 928997 305619 173653 405431 796…
Output: 528

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Arjun and the Tightest Stretch - MEDIUM Coding Problem | CodeTikki