CT48646

The Ashfall Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the ember dunes of Ashfall close for winter, Mason must finish the scrolls ledger - one figure at a time. 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 <= 2776; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2522 133159560 933871805 839529216 257446219 733099114 700343642 332685816 715543366 105220423 261766493 919504232 645461995 599262430 714447895 688979881 695406079 661748075 166675631 424465044 361042456 39715529 623203482 183967136 631808403 251420081 953892247 805271314 634529607 951335434 578587950 957678184 279377969 83848934 460854472 702281029 86443060 548647939 65725627 525845458 957461496 769047948 953293363 427795733 733336289 299599005 640458 987413877 437404625 500870315 386891330 79899470 446577051 414379861 723125681 178185694 905334493 111615461 34612579 530374217 640841901 641757501 666706311 70924762 640609410 764552541 976819781 823775746 801038810 970637917 203450173 942150528 587896667 465543571 448823664 744951438 800512260 884632975 164486552 702371629 232444828 80900…
Output: 1250348968727

Example 2:

Input: 1796 346092456 646417241 452567277 588941898 490165009 706192589 857289599 911731790 262736662 108127712 330135363 826820392 795479920 55164308 29768994 117835791 318390194 224836095 35983856 890591633 895088837 632219647 788664149 601026784 774688926 690312131 297379238 79409118 812953521 985185947 823464428 361609316 722274022 332346719 634278907 442377919 968364836 565900885 5397670 445689909 330438869 400042404 466435921 119994214 585944884 458901036 706072444 768554343 295265181 881175064 745911937 882731175 494327743 158994784 412455892 166908588 185510782 798572732 28977199 766348147 188495785 246202236 193229759 867210160 616904676 935704974 835579358 191949904 904913150 622717946 296523265 191672284 424964658 361929062 994654444 136010486 668578020 983236885 279427970 622302728 58…
Output: 879488154856

Example 3:

Input: 2078 867446893 929968625 883488608 129828371 339148996 441045126 781111865 922157100 463720230 78009680 413574878 160604614 998478809 887443514 798283030 618145353 163859869 708649076 364420964 580671462 445499867 113363746 386142133 835300309 781459918 118605104 126502023 970004198 670942555 762207013 255734703 691783166 455098675 581747247 966920769 496930395 11017612 308055422 626039255 171753352 941381723 187394588 162872312 912151889 319391210 141826680 343986074 821093061 972528107 706747452 452276333 848655071 47326839 830397453 49178248 954608572 452354322 893945728 170029042 485406096 213803368 317970977 201039212 710952987 922664253 742809247 651034498 141994199 3412827 762727513 686372695 435254461 710212138 740805755 125718232 284278862 777881984 394198733 400942416 458179783 5…
Output: 1019631834577

Constraints:

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

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