CT43155

The Tightest Stretch Beneath Reedmarsh

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the willow walks of Reedmarsh with crates of stretches, and Wamika the accountant must account for every last one. 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 <= 2960; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 1851 877011 264 912 330 327 622 878 436 894 233 44 195 735 400 560 141 33 965 521 600 258 928 533 450 626 236 698 338 834 924 979 321 447 360 336 988 169 67 963 155 81 765 731 140 21 126 528 95 989 323 24 248 610 718 954 903 57 880 367 929 566 161 337 447 493 711 384 885 792 848 624 972 843 189 612 492 688 701 540 54 460 946 264 292 888 101 399 257 188 251 352 650 47 820 650 402 556 801 102 67 738 773 717 863 149 357 424 597 109 351 402 764 30 129 540 588 975 562 463 37 986 764 289 546 401 826 282 550 326 44 69 270 984 416 906 35 722 899 98 489 92 719 588 263 328 848 177 16 246 443 126 411 469 895 364 285 645 556 325 98 490 266 234 304 275 845 403 569 574 148 75 316 857 176 207 193 850 588 569 442 433 861 56 114 380 44 740 563 755 752 328 223 264 28 82 682 87 437 941 108 490 557 613 504 26…
Output: 1766

Example 2:

Input: 711 245526 910 745 195 385 85 470 434 564 784 78 182 792 261 888 492 437 643 255 364 73 879 70 909 972 522 146 353 551 233 635 183 71 108 277 73 736 580 268 281 614 206 966 325 364 277 666 813 6 233 130 296 113 455 433 713 46 639 428 442 90 703 297 581 435 620 314 5 482 538 316 585 296 415 293 968 952 834 945 109 401 306 28 602 163 634 95 351 202 365 318 121 77 566 466 559 583 204 198 898 321 576 265 340 706 805 330 535 731 485 215 44 998 695 514 713 787 639 65 244 189 446 175 776 116 955 942 963 37 206 825 49 662 492 177 19 553 995 128 90 730 380 873 422 769 281 29 33 946 825 872 156 520 507 747 187 25 265 126 611 877 950 816 280 849 534 631 122 440 726 709 912 450 406 892 94 629 929 662 734 498 508 652 665 493 840 345 664 939 934 607 61 876 332 871 943 605 440 854 455 342 973 718 548 987…
Output: 480

Example 3:

Input: 1491 340124 907 211 146 48 410 105 250 40 943 899 271 372 820 596 769 374 803 922 32 472 494 721 693 707 45 120 477 529 856 615 970 516 566 803 362 704 754 66 54 670 463 638 156 928 76 549 128 153 138 552 832 732 696 534 799 690 324 26 482 469 92 211 374 491 776 133 619 381 549 975 270 789 609 684 687 12 670 104 941 901 881 139 455 354 820 945 106 660 100 686 262 885 194 535 41 433 814 710 942 319 731 329 471 970 670 273 988 399 797 529 905 530 431 201 882 85 88 982 253 410 8 377 170 803 977 340 124 526 602 494 429 714 443 713 467 335 386 296 661 350 139 387 272 886 970 495 641 347 51 519 935 357 962 409 390 30 154 687 25 435 681 336 2 334 438 163 546 342 879 916 131 584 824 836 771 158 518 81 829 846 791 745 541 819 271 269 141 100 641 469 853 389 3 148 769 585 804 323 718 538 823 693 169…
Output: 642

Constraints:

1 <= n <= 2960; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Loading...
Test Cases:No test cases
No test cases available.