CT60569

Eklavya's Scarlet Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the ivy courts of Vineward with crates of panels, and Eklavya the clerk must account for every last one. 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 <= 1257; 0 <= a[i] <= 1000000.

Example 1:

Input: 548 473799 560161 476644 474916 938653 660114 111486 21363 948912 523007 791553 506783 351922 486574 22499 656434 947671 869247 120730 55315 307882 582565 318193 829423 104592 62610 772634 428925 162335 305111 782268 875061 500478 8108 140211 874668 119374 581283 921836 418376 981959 281919 56408 313806 354696 602269 971770 912816 263569 571529 626793 157753 40449 38755 32314 472198 605691 299767 304474 390185 721186 59634 714184 418507 168687 439824 898765 504278 57364 566957 61873 812624 726738 153113 998374 58776 745663 196881 474533 433877 878378 442188 906000 295842 799530 950675 924712 275925 781706 279193 701989 760925 175860 572910 509708 461768 195687 283850 825750 222702 16165 660314 560021 922425 628569 861522 825284 156428 230772 178546 387332 692823 109048 461655 537869 92530 …
Output: 271502335

Example 2:

Input: 101 588857 435995 280855 277450 917459 925188 989466 577343 3450 885832 780704 189754 746263 724878 413337 105265 664925 924809 754820 891553 526398 682578 123871 460679 329190 549225 590607 503016 40677 249851 171697 183574 692558 960715 571394 467695 531763 793704 215030 387906 147052 589100 263786 40675 510464 791264 30044 990854 915186 154634 80604 486918 262127 690883 194362 925411 957260 960003 748940 963826 316812 135646 82500 229837 591389 984891 457224 265520 709082 923324 1361 101673 968647 714818 861546 901750 66652 862633 979359 982976 395824 160113 858051 990139 582907 338417 496659 138551 921236 44193 93242 455294 292909 990587 106066 113401 225629 606026 390886 283428 714143
Output: 44173973

Example 3:

Input: 1176 200774 389077 680786 795293 378942 479208 709330 413296 307074 48768 721195 586084 441984 800240 374596 135149 745016 174494 967309 946498 68520 865300 151241 371521 387037 546325 240095 316350 637869 279602 986603 703204 626982 759894 698800 526750 666107 556492 433985 658455 38136 908683 146449 734427 872846 9906 983081 995038 113629 867256 453515 41738 188546 966327 256790 125762 761340 374706 266542 26401 786035 439264 510392 19659 370376 257298 465165 820523 534985 262003 435015 659865 53386 943227 689480 791038 84343 615732 486607 70176 554771 140886 216333 300904 867862 829920 539836 97899 572171 580890 198833 871186 274918 505725 760938 430824 71101 659925 233787 285041 71987 755017 536473 262760 982911 18825 480611 85034 604605 151253 158416 172634 751566 821394 322030 160381…
Output: 585813152

Constraints:

1 <= n <= 1257; 0 <= a[i] <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
Eklavya's Scarlet Ledger - MEDIUM Coding Problem | CodeTikki