CT47425

Tara's Scarlet ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the port of Emberfall opens only for a perfect tally of ribbons. Tara 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 <= 1952; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 1531 234366 511 423 490 343 752 438 774 332 236 471 404 781 236 827 47 967 834 374 919 471 321 408 384 213 535 179 580 954 121 3 663 302 869 789 508 106 59 120 176 808 712 699 839 387 507 608 990 707 172 853 918 522 914 135 768 577 813 122 362 759 681 784 239 382 62 760 397 257 540 523 467 428 897 891 846 896 640 81 38 450 479 679 78 390 329 916 153 937 366 855 292 163 717 611 633 878 110 208 24 368 270 951 576 803 511 746 219 759 857 731 379 631 486 753 429 112 284 451 491 235 245 458 482 700 917 792 634 62 5 441 592 682 759 633 527 269 909 922 712 58 936 866 587 425 27 664 546 277 109 490 574 536 668 370 864 869 795 931 555 172 160 527 681 273 139 549 551 695 757 741 438 187 244 546 329 932 241 532 831 362 892 253 635 417 267 277 166 632 339 200 923 230 579 962 376 13 781 568 143 712 841…
Output: 445

Example 2:

Input: 1548 295622 308 499 68 293 454 995 926 219 720 371 426 434 551 137 370 347 305 301 258 958 106 152 971 207 406 34 683 180 660 577 769 250 858 87 611 573 883 69 394 804 136 265 685 120 712 569 193 389 842 500 403 890 363 793 531 326 694 786 662 481 879 594 878 956 646 818 780 12 450 867 940 146 674 167 271 859 816 656 710 106 766 547 712 816 291 327 511 573 123 418 853 980 189 227 828 731 71 314 656 603 120 71 585 373 680 227 932 88 931 892 778 26 336 490 791 216 497 152 630 80 31 71 543 534 99 89 978 85 664 574 593 545 601 65 63 711 901 472 100 155 656 12 869 275 741 867 901 585 883 299 154 243 39 877 301 312 483 340 988 806 512 625 119 862 46 30 531 794 509 713 53 266 190 846 688 706 391 855 744 49 564 882 375 951 653 217 256 911 142 581 272 622 151 35 910 902 644 803 647 919 274 477 377 …
Output: 568

Example 3:

Input: 1614 439651 389 280 487 557 661 173 422 129 26 221 837 788 23 374 791 605 357 780 69 804 186 55 652 734 766 278 549 651 269 869 661 659 716 315 286 311 23 466 218 441 888 538 506 524 885 221 403 193 671 915 118 118 809 971 826 848 503 262 287 464 575 994 9 708 17 442 818 608 887 403 880 691 998 312 411 995 491 8 178 506 711 486 488 108 559 598 289 285 805 191 848 902 524 618 494 890 3 26 530 436 798 37 217 379 177 268 287 862 558 219 24 634 827 130 179 328 347 402 198 91 525 663 212 264 230 917 510 111 470 722 175 610 591 878 100 231 705 943 417 299 594 263 127 257 846 572 510 397 582 720 239 119 868 275 964 70 701 381 118 766 337 323 801 661 279 343 677 782 701 711 199 146 836 930 271 755 708 91 840 212 233 618 802 107 865 500 147 667 331 734 499 129 287 682 891 307 223 863 696 755 804 32…
Output: 868

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tara's Scarlet ribbons - MEDIUM Coding Problem | CodeTikki