CT42761

Theo's Radiant Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The scribe Theo has been asked to audit the season's records. On the desk lies a long table of windows readings. 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 <= 1433; 0 <= a[i] <= 1000000.

Example 1:

Input: 965 480151 871567 714001 562995 649758 427272 412159 627422 193547 813806 661818 601626 561136 635231 587521 206959 586228 721738 183036 715082 205115 523210 4497 819629 669115 435496 488580 21244 944604 992947 808796 865486 929730 653992 412595 78429 104780 398885 493203 283755 89019 556409 766412 689905 797879 879892 401110 475013 406667 401698 419656 143377 438619 11259 525759 879909 309704 596436 438650 452922 359099 408516 171463 728171 297037 339557 933923 851560 734079 20753 654825 594643 647501 335694 745741 538673 45022 46692 263193 284573 166286 528335 369619 875976 770260 500586 448614 674822 274811 898031 523323 798988 509396 671839 683256 542214 849480 831498 816353 732839 844343 640296 628827 65994 590095 670366 141555 286026 875284 866879 622843 894371 186596 711247 387298 5…
Output: 471889369

Example 2:

Input: 1433 530553 597585 820225 188646 782336 335302 819012 32009 426488 864329 733005 520875 441106 424333 807179 248480 69159 270767 489271 599174 840814 98169 310246 27441 867994 926914 298565 424433 832678 712847 915056 524303 268797 660874 40249 370987 598099 999976 385163 69762 28566 692678 338474 131743 449369 644302 455568 2944 304636 716183 142608 179348 70973 136886 831053 409063 108502 408384 951065 89694 592029 291708 56522 509004 493937 272863 834193 542870 47303 832242 280384 281372 741612 502604 278450 592496 918598 86198 134230 227060 986170 819 400727 523098 918440 742622 550315 793799 517833 858536 478715 245268 949240 853432 868694 424999 563542 510778 699560 514508 174015 94418 232865 797554 136400 277332 586620 592393 859367 230983 573357 880005 78636 466343 520558 918429 50…
Output: 709665446

Example 3:

Input: 72 749149 614571 982065 265093 486910 466527 556771 835713 563702 520375 331213 753047 132256 752822 552643 745897 322033 593198 794101 754359 241280 336661 7004 276499 19742 413157 857029 996084 436805 348724 746586 117067 921858 878354 953302 669527 688881 444379 445149 123965 556519 190348 707957 848321 476981 930207 450028 815266 645269 327790 428688 195335 93101 260407 824771 234167 290207 775373 9126 318879 255852 149445 884864 511735 833925 72243 175310 407336 289905 166449 293387 782154
Output: 30241171

Constraints:

1 <= n <= 1433; 0 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Theo's Radiant Ledger - MEDIUM Coding Problem | CodeTikki