CT53443

Pale segments Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the cork grove of Barkhaven, someone must plan the beacon maintenance rota. This year the task falls to Dev, armed only with the segments register. 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 <= 2800; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1472 384422142 386618405 367291459 470850889 909321138 657449778 110006593 779621732 996246785 299224779 618929122 533466550 136846303 969407763 340552352 777182698 88584961 244463928 473883897 281408361 731766845 22078047 762838246 872557542 802385274 843560496 156092345 648689939 962926431 374832173 913738407 846815070 40256583 826439982 158413744 154259850 150515919 650740010 659137803 884180861 490509062 859762682 238540385 262908567 315145313 832909677 457234321 404607371 558160075 642011724 334936786 811843949 608636656 619233603 149330141 653644212 850474108 486715454 587566621 318487991 656710390 797964758 692373926 285052435 679022036 96314491 502936914 545766457 893022589 93656828 426737604 587014305 627179323 329788692 317514637 858359652 230302155 999492981 602950075 839417099 …
Output: 723777249444

Example 2:

Input: 2086 279579422 143462706 884943078 123131894 709681448 805971904 776527614 411504185 298662843 443363854 187931239 872890775 200076552 323835915 868696551 57516310 433835911 125532116 481165016 341164755 747170522 26052476 483077769 890229036 994629952 709676782 138323547 87673429 925788562 132444290 105847565 174557493 666437209 870694107 360893990 797081182 250618399 957037746 38534655 474789890 230759371 611072729 262896746 105912763 875971660 285098928 527394222 826659215 644978186 260361089 535233341 482958036 769616108 427606169 173114347 522285021 877638612 148316053 486780090 924034963 195871462 998323126 31890969 645734719 831141243 603657417 378151246 939435084 130351657 36879540 138303694 294350597 310483331 230159089 240137211 433302801 626514595 134267762 194601142 351067750 4…
Output: 1024324808142

Example 3:

Input: 1890 914182345 894082573 32725666 80773427 722283175 358614938 190216947 159148002 616916543 191759742 933697000 617316398 45011884 316084553 979149733 746310882 688955576 89168962 306326424 659066882 245392352 830588175 593015219 950420704 977509174 448667684 610695279 324686071 444991287 95529685 504561985 389203080 192893214 388453525 801483355 353881640 47523823 867146229 767715181 604597346 571451540 548872908 168501723 546043515 164362241 18786749 233167560 76982447 262772229 286939624 654584801 910547403 732132724 226850944 420495975 890037236 764109340 404816176 443037964 484720956 473159759 186413069 100125552 512044876 64159206 499691122 527107313 320489092 202884562 164175484 449375066 832433793 499724082 432782760 175903516 438103406 567565436 229046682 407046560 372800049 5864…
Output: 940250913225

Constraints:

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

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