CT50152

The Tightest Stretch Beneath Brasshaven

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the old quarter of Brasshaven, Rhea records each panels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3608; 1 <= a[i] <= 1000000000; 1 <= s <= 10^18.

Example 1:

Input: 756 267882991050 824481592 276122842 12339342 442693761 207770235 108789698 97058922 817903327 1236413 941583316 249876681 804715360 634738634 738183447 437165951 660702810 586907371 40921032 983423721 483101628 536539999 158769894 399804272 187470062 416024355 337331488 491930628 464059794 980319350 896012881 681244875 299180074 15798614 144615454 177649764 489378656 404795287 809808623 721124441 678212354 487158370 49208908 705433419 337880067 371150183 74890837 306419380 39667474 478312931 427415598 204069616 762669057 55395057 230822702 203097610 222592053 275880583 643459468 878433638 340652045 218951150 875215415 595689883 331219111 13188022 102353305 687958739 442495007 519345627 470954444 481972188 477520667 31675019 444731500 986415774 39399338 351037965 579339490 639011219 815886…
Output: 536

Example 2:

Input: 3469 1189930539904 521563125 106981358 719157822 677992099 257211815 445900341 628542747 110504253 669826026 884409002 679891168 421436334 203935182 202070304 755573422 159709650 59172905 667716148 792687098 357955984 217330588 69166035 748916777 995605878 182944676 251468001 588269974 569252516 612617791 328006749 642679954 866360032 245611479 431700160 818269420 974658797 960375102 173786711 275517444 764823182 364520701 166077247 73519110 337421342 663317873 559712317 796770648 665422788 518311625 961824508 571353358 681353236 596522564 790473521 578060634 853814066 195217081 916736176 601490737 237923375 131943651 201030029 150386049 428067498 346591924 14995466 459723103 898456078 336978023 378504541 278263481 351828265 829836775 713444153 100534710 63594294 159521536 605244798 804957…
Output: 2362

Example 3:

Input: 1851 828928549433 679822446 346785045 436226360 630874071 686541162 154420906 853117915 185377615 189957313 9339149 536315974 536306381 424994604 377060303 568077482 112976451 690788140 777258196 207162359 56287830 66463004 380392986 240634293 919338167 12247712 796030880 710985215 705589557 704056227 298026180 692572405 681715271 437294078 858615976 487910293 685512309 762055783 648269773 793103169 761061663 281423387 660843484 688180373 912549846 16057249 973650352 826176055 728712531 464185445 270753807 272845619 482246152 121386776 434977085 328339814 929997402 604626541 214759764 850721448 194500696 557603941 995192108 90078737 366797712 144998045 425310305 823642715 545282104 631587245 185864116 13296546 329632460 166534115 312920498 760367654 231889634 650737244 806986808 66246162 2…
Output: 1678

Constraints:

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

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