CT44097

June Counts the windows

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the lantern reef of Glowtide with crates of windows, and June the surveyor must account for every last one. 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 <= 1938; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1573 635213793 416235805 987308843 942226267 180306783 635311400 221012803 273596214 38852405 159192866 3658950 834791354 998458648 276303848 670028661 911062014 846352501 960924218 352240590 177317832 720456924 109739176 181050231 309340213 22890445 157646499 64489358 161576518 738174062 71916479 59119534 974153250 612310653 454838012 769272303 579257875 846751140 275169526 142621025 565180322 367753065 659110704 463739645 115108999 835583192 213106524 14793143 580426359 620165246 667490725 578743337 582929607 1933136 246158544 645275404 825019699 961661455 284222381 694565442 3587036 158820867 786320286 540055915 3617268 373900912 674616455 614821745 924929787 453731875 660501709 508606201 184939318 924307012 522163233 907285118 933112487 378072914 152494223 980909763 405344702 441087913…
Output: 781865954491

Example 2:

Input: 827 717567061 441820707 115433040 972318452 480989748 823084320 370436627 283171849 492611011 57210183 174115349 210004702 993198783 46155034 491084230 43604522 186380093 544818172 713656595 462467908 511939225 32871474 2309496 221092115 573738109 177512725 90155975 129686817 271065350 182544311 73220187 625723823 789676990 929213151 352639529 823798025 772037284 314419144 595725873 881852178 630380355 942993927 59178931 311912341 261891770 972735324 252326853 601095748 834013132 299363647 175101838 110755874 190292182 5251793 15678112 148602453 250791258 451506209 119570262 68511040 920403342 666357402 418521732 646365880 457727888 132478720 655736720 834988140 245304561 422426571 836871171 42968604 290415289 651561909 39321349 366674634 820052505 237972011 415359785 347078119 30681474 41…
Output: 413643448409

Example 3:

Input: 1313 597318428 624221636 339327857 688634626 887442956 175078897 73768302 770006730 771265802 366824588 113517002 911189062 488258054 713723678 728094924 13744101 437807826 902374156 977778230 148383769 837254504 327137746 780291986 141409149 394023044 584704634 543875754 338660523 974751628 698884148 158848408 834393311 244351888 591062676 27753254 488984313 606709467 775462776 88510939 341050844 917863766 186747606 918413443 688703506 559555481 50775086 200135939 448918120 666772273 971362472 456282876 627699011 153622171 37957898 487940986 505628420 450322231 674756835 878421194 662723980 592823592 867436686 333551181 78391503 880216964 94331883 432591202 633079136 219986741 991157335 722038281 331523799 523217989 315230594 304395102 549194482 653148628 48416920 758788238 813721564 8380…
Output: 653183679014

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
June Counts the windows - MEDIUM Coding Problem | CodeTikki