CT40842

The Tightest Stretch Beneath Grapehollow

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the terraced vines of Grapehollow with crates of scrolls, and Uday the log keeper must account for every last one. 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 <= 3339; 1 <= a[i] <= 1000; 1 <= s <= 10^18.

Example 1:

Input: 2507 826442 709 26 137 187 557 359 359 720 776 382 140 169 176 357 376 484 350 832 950 852 727 438 815 261 91 807 234 625 397 231 730 171 475 915 948 966 858 313 565 122 422 590 572 598 879 558 600 915 414 507 534 942 936 646 235 862 373 777 132 880 683 638 807 276 222 732 261 110 599 990 456 652 489 806 210 682 355 810 275 198 673 37 151 91 300 716 633 838 654 213 61 741 783 21 257 231 486 295 454 895 386 166 571 166 200 125 594 815 993 208 230 998 837 109 460 860 32 707 910 299 550 66 268 218 634 282 963 418 241 603 790 426 924 573 894 465 566 590 903 41 960 791 239 342 399 93 991 46 21 448 995 863 866 802 706 598 437 160 24 699 934 311 762 394 565 743 593 404 174 310 772 998 654 413 345 777 926 98 364 812 710 442 766 299 484 108 218 125 175 721 256 694 365 24 371 958 918 676 265 461 820…
Output: 1639

Example 2:

Input: 1934 743627 343 981 559 579 404 859 311 441 936 265 603 368 967 163 267 462 559 311 308 454 743 509 836 464 776 485 372 511 441 999 715 365 833 310 375 876 702 355 843 282 618 371 317 960 999 420 694 876 856 116 844 292 698 837 90 118 129 947 502 261 622 116 992 454 229 510 852 360 301 856 969 398 849 608 203 93 341 111 804 58 506 188 342 426 933 771 172 61 305 387 748 739 545 586 315 768 199 794 209 967 222 504 470 391 767 131 242 263 732 867 989 312 543 236 215 740 115 356 229 135 106 907 591 207 849 527 583 256 659 985 603 845 453 434 454 264 824 835 344 953 466 971 751 530 159 500 182 847 719 544 54 745 274 753 612 623 620 212 71 737 821 228 576 492 469 934 689 233 262 612 490 390 436 470 279 257 195 931 607 361 239 358 366 880 395 917 705 80 442 909 120 484 360 537 474 94 405 709 294 …
Output: 1456

Example 3:

Input: 291 18096 219 405 793 19 909 439 570 611 89 478 149 707 483 13 664 989 772 761 617 866 551 69 512 455 942 418 316 131 909 147 860 228 469 855 235 758 972 463 1 592 437 399 564 48 563 68 293 764 377 237 574 308 510 851 965 664 898 269 486 900 56 676 987 719 802 235 155 697 162 848 235 622 641 641 650 107 607 121 388 203 100 729 376 489 345 585 824 1000 291 746 67 442 443 351 438 959 395 484 555 487 317 678 343 857 633 249 371 609 506 119 436 370 257 637 594 418 796 864 247 261 44 947 359 981 957 228 247 695 267 890 933 448 388 79 415 83 868 167 82 796 885 910 379 552 938 825 225 197 423 30 446 662 275 645 230 745 263 164 716 407 43 755 12 991 209 564 972 848 771 554 619 269 937 463 417 975 640 250 122 810 251 743 485 234 887 346 412 667 524 210 645 126 624 609 932 977 602 581 692 417 303 27…
Output: 30

Constraints:

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

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