CT58404

The Rain Ledgers Beneath Firewatch

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Before the gates of the caldera rim of Firewatch close for winter, Manav must finish the segments 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 <= 1296; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1225 862418894 951691514 352976279 632446738 423572262 341816731 905236397 478453710 495479252 150939672 20121304 39660524 509836775 817954413 582507912 345910830 379547587 274595665 410073578 217016849 195626847 661585680 120201458 946910756 793596465 813669336 952027446 993105017 827808360 882588166 662129297 917606088 695622514 895529662 667109987 944967576 53549152 240962145 991734642 431352929 435218812 444018785 251669951 965413943 232970767 261514780 722409436 516756557 860934339 197532071 95199235 909356404 483286275 547071243 865676813 268331763 59804426 137293080 97349289 96460874 281515348 245024557 131762256 837637716 722147306 647386253 664778424 741830220 675617655 864544220 86326732 868480516 295039147 284061226 844307766 448767606 967250658 496897779 372571452 826264056 825…
Output: 582585374078

Example 2:

Input: 223 822186979 26495104 12814312 539488401 763993635 295132738 668450074 572745574 572815268 837708205 560877643 121785651 385141845 863471196 897588048 695290965 208424414 703163722 805917127 946687177 695342142 255439275 650438323 646079018 488589570 908497971 87051828 652263023 686331596 313343987 48984147 106750071 48209524 770570069 719809339 690424185 242425469 454808876 191508571 349698449 361380450 925052498 1499641 400000233 307085957 236212302 63349350 698290548 552669227 831302773 286979595 533336675 981187366 110728575 636745499 673191430 3724876 284100576 500269997 819797728 883479356 704377056 630080099 305550057 95462563 466802926 853931453 114086980 266909196 472548093 604980456 687730997 467488492 487734040 188539893 491903089 946646424 884041804 629117783 745281559 5953509…
Output: 96182179108

Example 3:

Input: 1136 605501484 873514586 86622634 183490941 835912619 116435665 942442780 317454137 560825667 219593651 890943572 416580784 196490333 492102881 326428350 578762620 338626317 65943245 63418550 894733324 50723758 868985270 181152270 578884841 734570204 462805455 500303335 354851524 461300034 775444819 659654716 73958694 326693951 204060646 974307627 629130986 931362926 534416772 514148088 318098596 708381686 314226105 134587116 111639548 101533118 846170773 989638072 828961214 708119162 26207403 131534459 403244251 677489277 182859819 710518622 451395240 362950329 53684736 873536447 215539524 469962275 265472873 363181033 382867399 668840218 826130020 489802877 542166401 161918112 670219093 635319311 613971181 937905597 334632087 988430448 271829700 925909783 978838564 810694479 640283652 89…
Output: 564994821534

Constraints:

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

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