CT50177

Jeweler's Rain Ledgers Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the alabaster quarry of Whitestone, someone must decode the foreman's shorthand notes. This year the task falls to Jeweler, armed only with the scrolls register. 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 <= 1543; 0 <= a[i] <= 1000000000.

Example 1:

Input: 599 34645966 302262636 35874566 609028473 310591040 750128115 431403908 923432721 674472166 839271870 973446415 678048993 866801266 9363477 769678286 660183287 710789169 621648388 149131044 127717735 854226462 513633580 29235746 600421170 100199694 392739425 21533119 444797833 982020448 904304813 479655130 415829251 521639815 163068285 653741198 342161807 284194021 448857094 445550861 926025325 240603720 21092616 12417614 87881285 544239263 382666718 559590592 263077899 230559285 331076719 478749126 872655436 884325640 194102571 174871803 506591376 472539570 895193175 431712175 344204907 513073381 57889138 644639194 900685056 198851291 312480732 900615985 141407005 931310755 152606589 796485910 109735012 68885651 301775508 506419810 549583223 739683642 919879227 373881984 398396201 2348407…
Output: 283095549331

Example 2:

Input: 1212 178594811 51609547 230757370 772083242 880723003 338092842 147483287 141188300 638633735 705836314 769248009 71430155 449953355 89878130 591114287 326277724 336028123 602116539 313370040 975929500 637788337 768119786 561517218 635502704 761034 396566646 316704113 527695226 863246008 957887442 327961644 716334259 529587957 561482478 143455418 954383885 417122680 666693877 335910154 961484400 223756118 885815308 511665882 25312907 969420156 591528103 80198456 591909284 25058017 14037066 856270982 552641426 709046929 14289919 93423554 227676264 951723836 158117839 504458269 959493988 542814756 907548241 391876902 132942508 20342369 669881973 348445038 241972506 348651041 615195002 561405133 285893305 603844908 279882398 211805848 700704106 796028547 869199190 856552558 840449748 47649603…
Output: 585873977974

Example 3:

Input: 656 680662142 979854980 893601224 915392027 639251906 296509824 160779987 639555425 459707806 269265688 265427523 971311022 858402707 427594993 195026675 744908025 285793517 740420201 790334747 609092543 191247442 274310487 434816484 229091547 370153527 220568594 139946314 198495026 560195012 601933945 600159520 661747304 478926888 595736455 843630687 778245585 407473800 897857512 693447726 406336067 540774888 175367438 796609988 293267120 116352359 594419075 43221408 597168595 396523633 634652073 790586417 874109937 260819696 220015519 103159157 28679315 711466407 470777490 76411695 125102150 155051463 853585555 722151535 938088660 998908723 733383579 228989013 654945872 804479503 295528660 637334893 915409270 671719647 703175601 121766480 85372218 268016795 760017368 476577616 632819653 …
Output: 329315784383

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.