CT50568

Tomas's segments Tightest Stretch

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Tomas runs the depot at the poppy fields of Scarlet Plain. Today the books show a list of segments, and the numbers must be worked out before sundown. 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 <= 2804; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 2212 250821 548 891 557 255 409 642 192 804 623 985 507 452 920 991 86 811 460 577 889 761 857 9 562 877 763 615 654 674 340 238 679 16 317 564 916 316 780 379 153 575 211 866 602 638 895 840 305 26 226 324 943 261 301 213 955 346 922 341 383 151 227 113 933 420 518 366 295 579 420 957 647 899 858 747 456 413 290 480 57 253 421 640 17 565 812 911 610 623 880 963 31 330 111 353 578 456 913 53 193 413 826 43 291 52 95 257 768 22 686 876 194 910 363 128 384 617 330 241 174 719 338 159 781 934 922 291 439 918 648 490 601 747 630 403 367 54 151 502 173 800 487 711 399 595 551 245 665 430 845 344 393 737 241 816 1 57 729 544 734 901 151 229 695 458 918 531 505 728 969 597 535 851 512 134 88 798 221 549 770 459 154 175 776 369 951 866 240 904 855 575 943 168 142 46 685 973 379 984 939 900 616 511…
Output: 482

Example 2:

Input: 940 458331 148 176 73 683 77 14 461 638 432 182 508 474 509 845 912 7 63 225 944 448 941 489 408 869 154 150 220 402 411 797 456 833 319 670 848 790 570 56 750 372 114 684 395 172 362 489 500 748 397 150 917 550 763 438 693 79 637 427 401 980 778 924 732 600 881 389 856 814 798 402 645 404 604 145 154 554 645 571 581 970 384 93 112 195 224 974 657 452 428 468 143 651 830 256 960 74 902 964 201 111 253 218 88 436 231 722 841 914 488 273 309 1000 866 245 602 284 644 829 800 578 361 206 557 67 88 543 136 45 454 383 88 928 334 142 342 153 891 217 904 615 669 260 56 634 446 22 98 50 894 779 46 902 950 934 205 922 878 178 881 766 105 700 354 743 179 180 532 145 380 987 910 341 240 954 103 537 859 31 808 392 291 602 271 28 191 599 457 960 230 652 558 445 806 80 481 132 692 172 516 121 57 81 676 8…
Output: 933

Example 3:

Input: 2248 638033 459 179 570 906 471 668 613 702 906 896 488 225 517 840 642 661 722 524 630 25 275 81 774 452 173 814 487 460 679 166 429 419 92 29 285 581 881 248 358 237 985 590 512 270 686 340 492 225 401 365 398 421 302 95 535 827 659 611 650 546 69 380 563 769 546 359 333 246 956 143 816 531 289 154 698 883 405 924 973 441 682 273 240 973 860 931 435 196 878 718 209 240 327 242 51 533 282 584 912 694 575 751 290 499 985 772 17 34 945 316 672 959 981 169 182 842 753 16 111 554 322 819 913 779 550 563 442 755 836 24 874 623 872 269 752 516 812 349 317 408 441 398 289 752 495 682 173 89 843 825 853 162 455 375 582 548 954 393 696 97 744 635 354 467 362 235 635 773 360 766 316 147 974 306 111 322 152 596 327 963 534 862 604 132 763 453 978 779 599 608 38 342 672 638 823 704 772 124 813 421 20…
Output: 1240

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tomas's segments Tightest Stretch - MEDIUM Coding Problem | CodeTikki