CT53378

Cyrus's Tightest Stretch Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the silver mines of Lodebarrow opens only for a perfect tally of segments. Cyrus 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 <= 3022; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 2627 185227 154 223 475 154 699 560 282 667 295 495 448 374 101 481 34 1 719 603 499 623 884 811 773 616 711 278 247 707 846 148 15 673 67 323 21 435 611 791 750 605 955 891 722 228 406 860 929 5 587 210 764 826 191 13 643 931 666 229 427 155 823 161 715 139 596 676 61 244 307 275 196 492 889 775 801 301 324 191 188 754 430 881 82 202 418 45 332 684 645 131 752 58 511 24 943 655 555 596 964 659 364 525 655 119 569 114 934 570 571 342 23 960 205 773 218 121 408 426 754 347 892 436 151 701 649 942 674 906 927 182 789 225 582 999 841 805 127 945 196 26 494 218 79 843 881 513 701 856 929 760 355 973 361 575 807 313 403 321 466 596 782 739 572 108 342 333 620 170 869 606 547 797 207 629 801 515 961 286 739 674 950 925 752 301 558 644 291 840 616 713 889 482 917 888 399 152 657 144 697 182 90 54…
Output: 358

Example 2:

Input: 2431 396703 139 5 142 149 82 79 990 679 88 713 601 726 168 524 954 341 680 928 120 656 399 790 52 106 11 402 775 790 842 305 429 577 651 823 817 243 913 700 386 684 730 691 811 332 480 273 622 80 410 514 177 125 167 839 426 963 449 882 617 143 840 49 564 433 827 71 165 541 449 599 258 218 233 34 387 843 118 508 654 430 815 745 22 975 925 984 140 585 265 574 639 713 977 555 688 260 816 988 866 133 826 185 343 499 985 591 524 789 946 18 594 791 670 99 97 735 316 289 245 686 858 674 884 93 82 112 213 957 178 151 43 719 281 358 615 115 377 602 702 60 366 992 787 182 247 98 834 587 181 512 64 186 728 446 339 153 135 106 355 743 21 784 770 374 558 150 605 351 684 791 782 147 355 302 72 935 107 379 20 964 897 747 746 72 602 197 160 87 106 150 972 652 944 726 213 415 205 470 486 245 320 257 400 32…
Output: 770

Example 3:

Input: 2192 426848 951 867 564 833 603 928 335 903 823 636 730 19 699 57 593 352 252 703 392 328 706 731 526 200 516 522 161 926 246 904 49 408 489 680 304 244 805 766 76 593 764 352 752 408 316 610 920 309 620 703 403 78 664 332 121 575 132 889 855 681 666 763 554 372 142 276 476 729 174 920 52 924 833 589 93 490 525 85 780 767 986 839 620 939 384 268 4 843 669 938 271 409 877 532 14 776 104 446 628 62 680 12 760 310 149 967 664 778 924 955 6 175 848 385 894 335 768 885 796 53 568 825 491 736 207 831 47 436 451 550 556 458 568 564 305 17 949 862 936 304 642 284 132 190 654 902 668 930 999 479 752 236 990 597 840 10 254 916 430 47 273 495 512 810 53 492 568 751 629 753 270 620 785 579 477 479 867 553 566 472 419 357 187 116 606 141 464 354 773 442 555 669 429 894 70 796 590 278 922 443 409 861 78…
Output: 847

Constraints:

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

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