CT50138

The Rain Ledgers at Tidewater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the coastal hub of Tidewater; Quin weighs the day's scrolls manifests and starts the calculations. 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 <= 3589; 0 <= a[i] <= 1000000000.

Example 1:

Input: 337 192327831 430436054 371618852 970738659 728747535 665341844 648112418 586226363 854599617 582349622 753462150 261873219 96602014 206034469 518346280 593290329 687666843 932893642 940940797 931599732 724437731 124539067 646912062 695820079 809517061 444205762 659811605 18833927 509441032 816270914 851080977 420530575 475234774 786727120 900277153 487419357 350546243 750610220 905580892 730235496 832777989 307116985 723532731 452785364 627329032 818981290 785018571 477279956 499118644 794786431 709573160 342665930 550552731 465561948 122379499 694875650 247565603 149990338 679552076 439873539 228520831 45001356 769398052 40473456 817142352 44445921 537957349 584398891 88685853 617582979 738582462 16944213 751793501 27178086 333170562 417779586 732833088 78077174 580673905 545601505 83303…
Output: 152918011197

Example 2:

Input: 587 781652287 260424568 554114696 294403536 340397054 11524198 903058388 487093478 948579484 556398152 273105162 131904213 476586886 555244369 941706579 212238926 180447030 610568129 514742514 297170262 667776391 515063051 225967215 820210571 873433705 760101572 311379044 213506576 823879333 576706603 889148527 195090745 286832678 600273900 295106549 970277065 179728977 967247125 415664765 31050917 95553801 422468999 968579180 280677479 86824616 951291943 676799450 386625075 369741541 100414365 328173088 249012402 846109753 933413690 96862768 337466463 65694648 776881265 308789812 980741249 760388405 783421167 281204927 723992227 516884559 951915660 610895723 986520907 706703972 224017976 71754029 601504714 52432610 687133186 218487042 399550092 389754194 210546805 239748772 896775751 8698…
Output: 283908057380

Example 3:

Input: 1378 239398630 41674048 286048653 165853715 341545389 780560438 23243259 759750145 915452918 608880152 28427185 134332682 888206022 79152698 784705654 981741290 487203098 274567260 555730522 124414010 970225516 692695132 200496778 273235647 841107507 209474622 75672566 9491621 47934735 54421209 427231732 226481703 330609264 455618619 794859251 732258794 646229363 782703769 269256973 559286866 32962417 429901490 523000579 83285488 346036789 803073136 497889679 85505440 505374902 151613249 841866228 244196842 545279935 757390486 366437938 835234616 17790104 243004376 377393758 209023355 218775937 981699797 321840478 175940164 13012547 744329109 953640327 931254037 315661598 236557293 333750537 795606053 450634109 438001912 909585296 352432159 587371430 979892242 31199104 11596834 240301226 1…
Output: 674957926309

Constraints:

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

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