CT43377

Indu and the Ruby ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Indu inherited the timber yard at the smokehouses of Brineport along with its curious bookkeeping system for ribbons. Time to make sense of it. 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 <= 2101; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 961 203679 217 710 625 15 124 313 158 819 1 484 689 729 756 167 491 583 417 476 51 303 621 599 68 148 459 838 611 206 820 359 378 946 651 206 878 920 920 716 396 476 647 702 452 728 871 365 538 161 740 935 342 440 103 772 469 641 591 781 990 776 210 886 174 790 901 886 548 219 475 564 644 44 838 731 480 337 388 542 904 637 712 329 172 607 645 308 54 127 952 161 505 458 578 599 729 749 579 43 265 612 516 551 76 879 332 930 641 278 385 779 433 146 780 930 26 238 590 789 614 269 313 570 851 217 548 866 366 515 46 741 141 207 763 325 286 108 527 454 429 920 998 489 711 734 137 243 177 196 626 568 835 694 497 468 770 485 859 442 861 135 851 593 923 281 770 21 272 76 635 778 320 827 796 512 927 770 227 165 808 325 695 212 46 942 71 504 252 2 834 620 57 121 917 67 473 123 191 183 235 654 830 371 …
Output: 407

Example 2:

Input: 1750 392921 426 320 204 47 568 636 836 533 269 347 935 599 385 875 79 705 85 932 459 466 554 983 766 891 522 985 565 467 435 745 451 432 391 17 344 142 745 586 66 670 747 836 787 145 32 366 394 14 99 308 342 448 560 507 590 842 844 238 7 60 125 532 474 580 981 179 193 4 114 89 932 847 482 963 672 842 354 339 917 628 943 748 429 800 276 36 532 589 655 381 317 13 18 973 88 3 288 566 788 215 390 218 42 765 849 144 8 461 734 981 8 10 874 865 656 902 937 261 456 85 807 551 933 676 517 421 210 340 107 536 601 789 213 55 832 116 233 803 265 193 812 569 880 888 87 145 198 285 206 552 30 176 380 618 564 252 580 222 290 942 872 919 866 474 130 576 947 323 736 410 484 548 967 428 73 797 858 653 200 997 324 815 391 455 192 897 362 361 445 141 344 352 862 71 573 396 943 478 791 421 4 878 186 927 701 57…
Output: 771

Example 3:

Input: 1461 668522 479 605 941 392 918 520 934 596 889 533 935 295 278 429 289 326 661 181 897 462 953 696 648 18 309 407 697 991 986 732 872 578 594 811 146 382 234 396 564 92 372 317 765 344 407 904 772 217 890 666 952 481 873 982 617 929 172 749 978 636 815 913 400 59 723 795 480 272 253 168 860 560 677 961 928 482 657 521 182 843 937 221 635 611 852 397 109 505 341 26 303 460 220 838 712 239 114 253 834 398 96 454 556 949 991 417 686 138 115 978 92 840 645 500 890 718 64 211 340 259 451 516 396 315 328 716 359 785 481 286 923 450 504 700 392 617 342 287 868 241 964 327 916 449 458 809 949 243 496 150 116 145 370 467 360 571 981 166 890 719 177 787 898 332 975 56 943 557 302 153 428 623 847 957 961 796 110 751 212 566 958 522 365 397 125 934 182 79 635 70 785 937 322 711 875 592 673 770 913 51…
Output: 1313

Constraints:

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

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