CT58238

Kabir's Ledger of segments

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Before the gates of the copper works of Verdigris close for winter, Kabir 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 <= 2156; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1526 115252531 468434213 203342296 711928286 296951845 513219528 952517028 244766388 897263321 160024470 470956567 171278707 591670379 798242136 785413222 469467621 125557230 462505739 233272094 537299259 326881483 933113192 928200585 787659186 337177979 301845830 997450512 723620712 596679842 575104020 24278511 299190977 317614077 405569861 671495885 367948505 658175446 597284123 606077948 742796502 277766803 487257712 835376839 173979798 985648539 543972769 128125570 970197359 794687320 306696149 764163433 684302169 326502119 370267192 227793099 814422038 412007260 361742844 906683196 827997140 93710656 916457318 662547325 132416814 478405808 113817661 626455446 107039892 130710018 412231037 521811723 847790538 396171342 22258433 315051282 615451053 5204902 773045310 925673736 918349725 …
Output: 759661778529

Example 2:

Input: 2103 124452450 692376646 812759364 719342802 1603066 372156129 769127070 718255206 225600602 849670514 266858325 327124393 486455106 199641502 779322299 414425646 46938474 682117950 11276149 650043465 647006575 729316641 450511433 271440107 270904645 328951744 877451364 907553277 78441320 604336362 431742737 86205099 620213219 454170795 188358269 884306332 201978801 639191475 278290349 382865098 880586828 157702418 292198063 805118793 735234945 337357469 122379973 161802091 925900317 848037720 988647736 771747192 356360050 205799004 133675594 483059637 602787051 724646278 194185211 141167746 628311040 590001262 771834489 996201873 427483135 686807572 827159854 542499006 935294030 270643436 405726164 314904522 194316913 927505438 985976789 383806903 555488628 392738948 193590818 16958550 20…
Output: 1041005348607

Example 3:

Input: 1671 452333094 289706180 506160086 116016095 264246121 607884530 757622877 180583871 175259466 612475184 948783643 616691334 775114457 506284819 166624361 124490768 915097242 795262834 696407382 495036607 676681276 114122165 787629079 81145690 126631687 788011986 278188745 9202869 227555126 270679643 524519310 153042572 508544053 819805101 366951421 583548301 856209519 454178606 776018092 276591247 473724465 228744470 105962053 862983710 791588010 542637692 55730921 184971764 414531952 851758076 898951026 69082824 25012526 415520921 849642671 517723806 154573597 23935467 256129793 471872286 183892688 794529185 846592052 846589025 516106837 892738019 991875143 632304652 171527035 839582955 999316701 994721712 38735106 511124870 202710879 83381687 545138769 689313598 312496929 269066809 1199…
Output: 828806816798

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Kabir's Ledger of segments - MEDIUM Coding Problem | CodeTikki