CT55315

The Windward Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Lysander inherited the brewery at the rookery of Crowhaven along with its curious bookkeeping system for scrolls. 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 <= 1499; 0 <= a[i] <= 1000000000.

Example 1:

Input: 992 845176515 528976885 323214122 194141676 127279108 189482556 544573075 180592427 930895792 13025502 892505543 302405453 425032921 47654331 538970170 219049675 812599935 682616771 156143847 371171821 702836021 336249847 293094660 871997264 754432649 893692813 40169277 264537121 48975743 776920938 354894557 371463739 929285705 790428116 797969196 598799994 647605803 80357001 340125134 761498685 186172247 44413653 957756657 323185570 8887659 752461861 410715061 13118930 711068371 407200932 710346847 280297116 324821028 950287356 477806361 481078725 187390403 414000240 340972039 230522464 235691343 418707378 787817213 661621894 183925357 299850363 505783529 580949593 576109609 236188936 558011855 643482492 640999282 369510498 979316821 587672750 979199167 259913186 220121800 795910875 49202…
Output: 479615537119

Example 2:

Input: 41 86254242 980243263 263424704 594591057 802362261 56203612 331338155 302589413 161818864 685016417 175861447 163523355 430649349 82929397 717817446 283845940 435993668 829223212 18152557 814048434 716298858 126254401 972879773 255779570 462195051 862661049 251394806 39560130 442276737 394362337 576461582 549874108 365578824 512541651 660049255 860646583 488714702 360470689 517393626 56853304 106338885
Output: 16661807649

Example 3:

Input: 1010 571226961 133635992 781655454 519570949 710071636 489165951 207832258 185053907 475303378 385640668 851218821 640699411 178361519 640007593 606556813 457397986 708451578 12511736 141544605 781660529 128207725 609209992 546724968 174870683 588898792 990683436 412231117 138056417 7269395 860944795 310741209 733565891 786751547 937164707 965998949 790624127 5016522 340854572 257731541 366550111 971301514 903756413 355357289 834066111 985833989 53566983 183750195 643634676 198525139 947796875 721751625 819879751 571357567 72318629 412823348 780478899 177509169 742105611 128437667 774546009 189228764 197803676 448589598 517735886 878976140 92535198 745531997 12017014 970261063 547991307 677999877 761708241 793730350 541040064 720797014 959088416 460057340 705625103 29696353 526814638 73670…
Output: 483852391234

Constraints:

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

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