CT61989

The Rain Ledgers Beneath Stonehallow

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Bram inherited the studio at the granite steps of Stonehallow along with its curious bookkeeping system for stretches. Time to make sense of it. 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 <= 2408; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1085 988203738 706744476 996112826 993398780 344936374 943504137 214638875 180935434 524969871 823873338 902415146 748604848 867399264 595490796 242265068 773553721 424676233 264859271 740418498 652809604 949506204 199064193 283902417 229593998 91877837 730746331 426212808 672991794 524388602 343753046 8143280 654606456 475304123 57951988 903387569 86096802 273783200 462384891 542894757 833545992 633476881 526066517 224495338 838821885 344933298 743748047 74608677 578620940 647052785 393049149 641533727 343001079 315057098 240911299 906010346 405289406 67758828 224930178 430547993 750252067 188533888 85675913 567520846 85075172 747649351 756967132 244096413 18150945 515208330 363620611 714256022 420888759 46494138 117792907 563844673 14307983 569605864 636618204 199962739 718053106 6250315…
Output: 537993548465

Example 2:

Input: 786 428171873 320911178 804897224 473594621 69149642 1504584 600949225 769346616 253678358 357096376 201267763 396970989 428330092 692999591 325055674 537060519 161564012 715074765 327814530 916677096 635103024 118150800 821022688 908198098 787031640 241152114 593557319 575667428 594860952 246661523 184615993 340469790 669077690 763673085 245657150 966729758 298302236 23743101 804145115 684517357 622386297 335977952 872584956 277951365 847185725 644252390 628968219 263743301 877466908 928582926 834280339 671798440 729819120 741446338 125134573 571217733 801080191 827948819 309612563 563803175 867331702 654232015 733382032 842269070 874148275 984552203 88188622 644406850 706852299 847488295 115102055 331844594 944822032 690579413 354826626 119547624 284102996 420962899 717277688 20386850 76…
Output: 388953568008

Example 3:

Input: 754 829509360 789587029 247110248 198080547 53006438 472807291 76263175 55477694 93261147 905153327 718356622 629880412 997338123 112073427 808844824 859950201 980552503 754471333 139937403 764476190 614106572 35970744 505192165 284755693 619158010 598581894 687834048 87051662 626389602 784673474 390872839 131818408 915396804 438406563 618663141 218217489 620473151 17631760 620461962 695822224 566583801 983331808 932722286 789149491 402348325 884707737 944617690 861913448 670706771 47538269 4410623 746228673 20496646 916613972 367316584 681873350 919793376 934771951 601694018 106749036 308687051 546319985 651658412 530241467 630295772 74605448 123770997 696926123 208787053 642162240 506027555 751446799 506724013 684187594 336734173 629815112 414409109 359595473 705270754 63807550 837448078…
Output: 370366795651

Constraints:

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

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