CT61092

The Silverfin Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Kate found an old ledger of panels in the chandlery attic at the herring shoals of Silverfin. The margin notes pose a precise question. 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 <= 1041; 0 <= a[i] <= 1000000000.

Example 1:

Input: 792 220426433 220526066 810083545 604061301 308195052 988083664 326822617 706526454 138736836 335244844 209844239 889573154 788936564 365205067 537923788 877962415 599925940 23421817 708846085 683685665 993344407 261960834 888247602 213518697 183590204 24312740 494869457 667031865 345372775 887940722 145368335 912190295 276796793 385359023 588519468 858844393 86235594 328428236 456042168 637719140 944360429 848534545 233254792 201519182 881139224 378653275 759653500 380360932 931369634 271043868 394047602 161509463 231369312 106201876 831455816 55732868 546022092 438854261 843232456 492197512 368756948 884348025 262043316 60578187 166303150 38844804 727595850 517421158 132964348 775222498 302658417 741041881 734067070 317882499 603198956 958351136 922336912 293282801 464902782 198166893 66…
Output: 376172880267

Example 2:

Input: 142 255367706 171916993 130072948 148166541 620319635 167291681 21621104 797750114 272187624 969596579 241708868 740809082 530308548 219610775 49876474 825631197 435616049 69205144 16237689 848628123 690203682 12820006 481150518 879827304 566925380 483673242 69077260 905469057 200223568 66580506 454343093 680463273 203915971 953309946 543484826 131544620 332329853 114872790 717687950 516461550 686829916 291445686 783176024 796775977 498091444 946765270 812879261 26729375 667389113 222279864 115174946 739219530 915840597 955434667 750328261 443634170 989226991 70508176 573406288 733997674 373418523 365501989 849879438 997349754 19491107 462232773 287177747 379665859 309866797 284991993 943469962 107527429 671637739 369206349 541923858 958477747 579079626 447795438 535510829 886117046 682040…
Output: 58502810742

Example 3:

Input: 373 11207982 260031074 668036295 143312208 903454613 745903136 583520243 111584163 761241533 285100803 400675398 462431490 274216990 452555899 119750730 303368963 258633647 227257217 554991288 495359980 869680965 991358233 806529526 351614866 961429913 366730643 95720795 816239152 890020449 673384542 705942819 734111767 886123227 960939678 589126466 236261732 490309259 461408297 720579553 243906097 710667694 23409813 317696471 668705993 677231902 974900908 250702997 498079611 402888943 559993171 118296161 120242045 217809465 320604345 432385567 790576330 257058846 159070974 797771219 809535517 287597948 26047445 632616809 390051475 601114718 484237418 334518465 22757257 682144957 159718483 185005802 397959998 378231821 161556983 840651605 293972855 999214243 85584629 414220262 852786116 72…
Output: 188242010884

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Silverfin Rain Ledgers - MEDIUM Coding Problem | CodeTikki