CT62561

Kavya's Ledger of panels

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the thorn maze of Bramblecourt with crates of panels, and Kavya the assayer 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 <= 900; 0 <= a[i] <= 1000000000.

Example 1:

Input: 125 252172548 4030486 701442129 337485301 146433533 496765090 876631579 732153443 907385700 468932067 31631467 319807135 497309539 894234180 408726661 522659705 691103107 950156026 514088583 818268177 883969151 358434236 641016535 300807823 125265868 705055101 350620175 850255503 72126345 745647923 457440159 688363317 55817818 892009286 682756172 210277449 628251592 851071598 75353386 113777365 778671358 956972615 363713283 259330724 572564182 742860480 39270072 217504911 534488021 871781613 15362679 624408557 543960638 116425176 422829640 572849434 912253404 511482119 577993977 260826332 246556474 585061517 401998771 840940040 384368322 798554149 17888137 973782321 166660358 225981608 215245446 593673399 293679069 539128275 944248630 364070675 320762013 887315571 24349737 13579540 7172084…
Output: 54709970264

Example 2:

Input: 129 459334378 606986229 141656660 427762447 601297854 716436896 316839301 292580282 263349049 511850571 804606688 716893277 687603100 477801906 560617579 79620001 483795369 919319174 253952453 767339606 107082821 320110727 12040070 138487503 749601671 951448953 994019505 335406929 44682866 367328841 777971097 451395069 977855476 280543771 526005466 699298239 648512019 539750167 157912606 508905820 410982762 79496164 120579314 746926777 665291859 11790430 572109518 963328139 799546372 356751330 179244456 292925961 62722006 326395742 390865099 154302246 521134852 332085471 960672101 487253421 389720468 823153443 205450691 381980402 704964084 403491167 27008513 271376787 223540225 360567365 138688979 191364184 183790675 364156582 364166031 299997179 689045965 812515087 727574653 347578186 811…
Output: 56660705563

Example 3:

Input: 250 230375555 328638164 340700522 469392535 733413143 800990595 919476609 58061753 308307244 796924565 303985872 888969251 858373276 885655480 355091242 312613619 192452819 525108782 634040494 520604429 365689959 13193499 591088438 406435417 989746687 522098629 199381605 714945730 57301682 251714021 720788790 489047078 874288522 421665285 281236889 828633181 347120927 458319924 946722532 871038735 156302790 294319280 289800357 351155451 49882570 372255041 953267462 440972408 649290424 197852998 44271052 613323740 134360504 680357431 556678850 196683691 379772074 483722266 545516001 685697994 662836941 911011659 612798553 929970769 426333409 162220935 827692361 485788226 409309469 560931115 958688407 514502232 204593642 569385537 8390597 932152098 345967496 803490058 279247685 108232404 669…
Output: 110348089290

Constraints:

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

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