CT37510

Last panels of Cartwright

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Cartwright found an old ledger of panels in the lighthouse attic at the shale slopes of Greystone. The margin notes pose a precise question. 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 <= 2808; 1 <= a[i] <= 1000000; 1 <= s <= 10^18.

Example 1:

Input: 399 77749125 941036 848455 725931 902601 801693 60092 145137 546405 8347 403060 75006 220102 60239 892720 317068 837768 524074 59122 114048 662234 270172 351956 369753 339536 257080 129762 180121 49948 960735 107371 28535 132700 268964 342567 590786 95309 44961 467793 487760 756377 736159 997134 980730 168264 178627 311466 633259 269943 601964 786069 463576 928873 361431 600715 960782 417429 12643 704519 160135 119672 281036 889790 881197 65260 564047 117460 57736 822150 120993 562991 564784 939859 177348 590256 870628 506935 492152 920814 723090 30432 342182 280370 206106 86971 557586 732577 752228 201238 568532 763171 787843 70990 15844 407925 447270 579299 212972 105621 188800 207682 591008 648084 732600 48404 553294 818305 523726 136175 706851 327476 77593 495318 700659 389109 535171 1…
Output: 149

Example 2:

Input: 2398 46378180 602405 954982 48694 533344 105350 751723 896524 420478 965008 775151 525196 272226 290908 606959 396970 575974 850036 292333 571066 160434 328636 810632 837546 187785 668538 771098 500197 623771 885788 446217 204868 580340 359788 353833 893229 290978 827047 935639 256690 227716 585886 703191 955998 242966 862254 997978 897419 667569 407643 227249 172833 292701 169726 479156 571322 987029 940742 299750 182976 974540 676931 559520 175883 827838 134360 325517 415556 296162 910290 191416 743857 278286 915289 227019 989615 563782 956226 824676 850506 70741 390473 904977 570147 172745 474921 647132 227150 786316 572999 195388 395028 544082 444056 507203 14746 144711 348768 319307 658844 372061 441958 824906 125844 742571 990329 413806 836720 658141 385804 387041 220450 196719 31373…
Output: 78

Example 3:

Input: 2179 123336569 190918 919894 388187 89253 81992 812130 332840 138392 801039 559804 104016 253835 625693 145806 858161 840085 47339 692197 373514 120207 952014 24247 224395 400035 397585 101904 117602 181688 633046 15313 827560 618380 111635 880839 791586 96272 255050 224475 827291 3930 39134 140459 988437 631137 775663 517161 671599 567048 362203 319462 393115 524764 648098 899854 825396 882119 102989 380534 470677 975961 540282 448028 334704 7761 572267 264948 758896 467514 319310 709602 621526 343763 549838 667720 982416 293574 248996 950013 953313 232113 505615 181363 665349 725625 970382 919490 668205 976427 953853 274332 227842 233868 708437 357575 405677 658931 824697 154107 364437 272191 546980 994033 782880 110473 305194 355654 125683 481433 33474 57567 800674 533462 501832 400500 …
Output: 234

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last panels of Cartwright - MEDIUM Coding Problem | CodeTikki