CT54390

The Caravanrest Tightest Stretch

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the dune sea of Caravanrest as Tailor unrolls the day's manifest of ribbons. The tally will decide the next shipment. 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 <= 1434; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 358 50393 75 283 145 117 736 719 743 648 249 470 942 159 686 828 162 79 753 221 428 529 860 854 890 690 311 997 540 270 150 693 712 259 625 964 792 767 536 166 1000 961 704 455 492 365 952 296 601 467 288 582 307 205 230 302 616 889 890 804 775 319 858 986 830 630 552 638 37 582 19 941 345 366 606 551 530 333 441 176 515 724 955 809 223 179 192 580 211 564 742 470 550 206 945 851 776 294 630 640 632 465 407 77 444 582 77 35 522 592 418 734 21 285 740 249 610 970 167 694 658 137 7 259 148 582 483 394 14 37 246 741 690 828 314 943 221 649 878 697 248 809 169 562 402 98 743 992 322 349 359 591 792 346 83 367 680 388 318 252 737 672 903 398 502 253 780 537 178 317 616 589 588 312 341 706 986 524 810 501 473 945 24 319 172 221 183 128 197 770 455 355 773 905 544 48 806 94 874 862 867 384 94 831…
Output: 91

Example 2:

Input: 985 456761 482 409 744 825 888 875 250 637 722 551 70 465 41 507 75 507 545 23 214 154 34 594 813 611 99 996 415 491 483 524 322 964 902 473 661 474 656 818 768 985 127 544 178 767 524 427 257 705 741 444 218 597 264 132 367 769 391 40 791 800 877 266 62 278 403 478 697 296 561 679 821 954 370 999 948 954 527 358 916 886 967 246 761 613 894 825 579 365 195 621 906 206 901 842 743 608 124 262 640 622 935 254 753 32 747 609 221 441 977 337 712 232 260 699 669 930 818 836 822 676 788 187 32 471 760 445 36 56 924 481 201 721 947 622 160 969 82 731 215 972 360 283 715 657 880 996 298 503 723 747 634 661 58 4 492 395 188 577 942 811 762 836 154 475 673 873 568 539 948 622 937 691 847 126 7 238 136 190 17 348 434 188 433 613 85 128 856 596 826 558 155 642 204 109 591 42 533 492 567 736 961 204 65…
Output: 891

Example 3:

Input: 191 89889 725 918 713 348 490 770 282 548 851 34 252 277 229 227 288 109 131 956 565 449 581 217 250 975 589 669 800 913 312 310 546 93 41 554 821 610 337 442 59 977 327 945 33 416 944 408 550 840 501 101 911 88 227 798 540 861 984 132 670 686 673 648 17 880 144 312 659 102 617 252 282 257 600 153 213 593 309 768 257 362 695 128 315 172 513 555 892 793 614 257 592 471 463 691 957 736 188 413 942 561 171 207 474 671 42 602 57 18 129 776 411 726 938 783 495 306 125 484 260 211 237 646 64 91 473 269 942 750 172 816 845 129 157 188 674 601 117 620 110 115 855 10 613 794 921 958 392 318 558 7 359 917 139 924 510 209 596 242 956 981 424 201 976 14 981 976 772 682 294 511 8 428 390 711 43 675 755 672 141 915 596 112 698 724 148 99 978 923 157 861 202
Output: 187

Constraints:

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

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