CT50954

The windows at Slitherwick

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the eel marshes of Slitherwick as Kavya unrolls the day's manifest of windows. The tally will decide the next shipment. Task: Heights a[i] form a skyline; after rain, water rests between higher bars. Print the total trapped water. Input format: First line: n. Second line: n nonnegative integers. Output format: Print the trapped water volume (fits 64-bit). Constraints: 1 <= n <= 3884; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2649 81265773 367879093 424095074 272111530 32511913 92437597 962231923 70116991 423085120 835423277 850302742 624915093 801043554 932141375 415264714 153250837 771444923 752850298 978091644 740487216 466419994 662984537 329641494 51581009 112730627 116663044 484032629 957805784 220315359 433029643 498829364 674422862 83442356 888205278 283545918 510783328 29464299 446488036 566747439 237744027 453579250 173496751 215507143 500527721 521187418 141132255 509823322 295307103 991506362 912583744 967762322 8443621 14846786 698698299 687260637 26101113 835211927 713125329 671669375 225462533 416172489 459670898 313376085 208493681 721961993 433546163 53374625 442280272 595529164 716878932 811011998 13414028 49985770 974158205 97190077 416329275 743856803 119501188 64302579 31110928 727149781 54…
Output: 1303062857147

Example 2:

Input: 269 290164077 978001150 284932419 213243015 999174524 925372741 110073141 42355632 488025446 44116453 645908280 432309377 461068716 633408883 8105682 370837483 161175737 818266875 456218170 537510890 276232162 200084160 531879964 398469157 996326870 958206400 719739665 220522062 197450605 469659436 186659393 461942493 871211581 266840469 999329235 698265560 781726754 183290957 735825500 600500217 448517161 213092719 288382961 293488005 70863277 144761150 716137847 188011845 535964930 629261436 682311974 979325510 445697873 28427792 623350713 327835588 295799198 738134938 441208237 52473659 153883379 174914956 684698704 363255368 885022924 965319127 138021251 423162665 767593318 721274423 992323906 6877153 318408432 245245519 538049653 830915387 565910792 804682845 721331076 283906632 36473…
Output: 137334479286

Example 3:

Input: 3769 142214863 889475378 85408110 776736874 655485422 798489828 585633467 988836202 478644874 705716565 15502520 639473976 236401693 440785896 729297085 847346796 539968268 624864794 405440226 942370614 501155104 161115988 496856852 550264205 520906254 934778195 861756833 444795789 171480199 93488317 838901982 902076482 476793814 822437080 507209105 919836284 700266964 482885567 926152739 499471417 41047759 506651948 631399632 475628436 886453004 975320374 133259867 448176584 463886690 917769919 672926819 158178004 710915585 307137368 368228514 696649545 785489916 20541824 908247980 924563184 411819917 111190094 490290153 966256032 67673166 753593631 789208674 360872643 646640171 637442876 259730885 927690005 490479589 781475178 871768293 735310352 849863638 665466066 775424305 906271735 4…
Output: 1859607959086

Constraints:

1 <= n <= 3884; 0 <= a[i] <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
The windows at Slitherwick - MEDIUM Coding Problem | CodeTikki