CT52130

Last stretches of Piper

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the terraced vines of Grapehollow opens only for a perfect tally of stretches. Piper 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 <= 3517; 1 <= a[i] <= 1000000000; 1 <= s <= 10^18.

Example 1:

Input: 1809 352600951785 16411200 191663601 291012006 850118234 738021908 687951049 114362145 842507542 357018855 948904723 267550926 27299660 453352714 445862944 155061285 971703193 59724446 527978964 989525708 244956782 162617848 847652228 269566727 443134734 290235142 6857287 501416332 857879704 600228510 476442716 515593370 881060192 718396655 527342085 966209209 309230884 455581925 974780083 182077035 875280391 626637900 418996608 273428799 250943243 278265184 383801278 842012747 808548796 929209733 377989832 455621417 303374664 721605156 640094558 43104093 528784502 852845586 996607053 137325063 410619934 119905088 84618508 439482280 496872364 570735348 602188533 210058164 360267051 418045186 536200985 219842749 652677370 423659523 908060501 920752615 328700540 772006449 571924485 207611961…
Output: 676

Example 2:

Input: 2429 75317869312 549908958 859336217 18901738 656050144 360648352 271972705 246673823 129248784 766421733 500025470 406755963 942243650 676706166 88666610 834668312 164920497 634285286 403138154 388064893 515508761 53870154 976314555 693624151 639575030 749057904 874407190 878724184 261562592 562684973 205504809 35500371 180621090 458696614 291374398 940421549 234116562 257944699 272817902 393372626 332441571 807121381 352638444 837703253 285606654 647091950 373963808 461819660 497145451 359236572 612683383 39273511 117341482 816669043 997917662 558658716 685733990 842449552 886310011 929024 783488661 512928250 208962883 393883187 628613961 445121935 477732011 609606260 526216412 434444757 186691542 572484711 257053976 334695651 464469085 744435103 298706707 262066437 193326097 333098869 8…
Output: 138

Example 3:

Input: 2526 499290805890 250616783 972454153 787852735 986128862 461673831 833880162 367618857 136523266 591796659 451903482 526590713 549623247 385909582 844344905 325939687 332993550 347587870 846535603 499934047 132707449 542734261 685849789 725424526 463238034 165143711 15459333 765513682 609245064 584174191 397338573 300279959 488603319 348250513 964610948 592147695 251256299 99571889 519245489 524504309 240056672 54121009 268169309 761745039 926313227 567032027 951593320 453218832 651120608 980104897 153933528 438013558 697896617 611126340 68915351 437274533 951032347 445964550 972182617 21241992 787866717 874915315 626657782 653556706 101713372 391024699 884773272 204261367 450388901 2410844 831694986 198161281 67084503 509661316 388771930 502584443 611500479 586875176 99219740 739572802 7…
Output: 1011

Constraints:

1 <= n <= 3517; 1 <= a[i] <= 1000000000; 1 <= s <= 10^18.

Loading...
Test Cases:No test cases
No test cases available.
Last stretches of Piper - MEDIUM Coding Problem | CodeTikki