CT35120

The Tightest Stretch of Rustwood

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the fox den of Rustwood, someone must plan the beacon maintenance rota. This year the task falls to Dino, armed only with the segments register. 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 <= 1981; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 1658 5724 862 735 713 453 823 419 551 505 121 536 254 23 182 868 110 997 61 181 402 369 134 404 492 523 821 304 134 185 541 769 740 651 623 119 237 599 733 741 66 308 986 827 847 460 575 177 581 62 125 788 737 118 729 269 700 432 348 112 996 359 52 627 565 626 264 353 788 506 167 187 328 215 982 214 517 992 704 823 887 781 418 552 337 511 951 348 255 789 698 143 434 750 806 422 923 503 357 641 662 50 968 545 961 424 145 972 786 626 246 66 826 648 312 544 931 295 461 763 539 294 420 723 171 965 944 530 824 749 621 810 75 829 492 689 760 292 214 498 539 300 598 730 776 599 850 572 241 528 559 239 887 910 552 727 441 117 119 988 93 918 441 404 110 865 787 1 985 6 742 38 292 922 534 933 163 750 213 707 150 570 860 887 53 493 162 46 445 201 401 815 869 988 882 453 148 150 802 629 546 707 976 60…
Output: 8

Example 2:

Input: 1938 133587 917 662 804 865 836 905 897 340 279 469 557 146 210 244 954 158 942 713 300 298 756 414 81 973 690 950 584 50 431 608 661 506 630 294 846 607 703 417 2 460 581 133 406 563 339 236 247 563 986 252 776 810 22 487 475 485 470 250 98 786 746 136 520 186 229 485 102 65 58 399 571 721 38 735 641 385 92 967 41 454 481 935 880 62 55 76 158 667 52 590 568 552 610 824 729 173 364 134 175 742 262 308 493 805 312 902 587 512 985 815 59 13 40 418 158 729 424 408 882 357 841 707 996 745 274 722 108 309 31 944 537 198 37 917 4 236 440 222 340 255 927 483 996 523 169 948 322 873 139 619 320 582 56 357 516 150 62 547 522 461 269 415 229 656 276 396 615 116 940 33 841 315 646 894 930 649 632 663 214 433 215 746 606 874 848 171 838 978 637 133 179 376 285 348 426 263 252 100 498 867 414 572 961 8…
Output: 242

Example 3:

Input: 1641 568647 430 937 232 353 22 79 502 564 242 803 179 608 488 802 947 777 242 673 207 763 953 580 125 510 676 782 76 725 531 669 416 636 421 549 679 402 630 8 343 46 347 442 569 635 453 830 3 707 423 941 465 962 610 969 883 357 121 796 521 288 816 587 804 815 560 815 208 588 438 269 400 80 812 600 51 126 986 865 469 430 269 524 407 151 346 54 445 749 151 572 9 692 558 419 426 389 946 731 13 896 3 692 457 898 282 375 103 66 913 381 494 725 541 937 232 831 731 672 35 707 551 15 344 935 211 19 233 895 686 167 423 979 1000 350 324 435 375 247 377 105 708 549 54 915 725 105 526 774 993 21 527 38 390 242 253 538 852 576 117 113 397 604 413 284 758 267 39 134 814 579 6 411 975 500 870 838 472 287 766 971 643 513 217 578 224 887 969 136 62 261 978 631 326 164 273 444 452 858 964 689 816 56 306 145…
Output: 1118

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Tightest Stretch of Rustwood - MEDIUM Coding Problem | CodeTikki