CT37314

The Rain Ledgers at Glimmerfell

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the quartz ridge of Glimmerfell, Draper the auditor keeps careful count of the segments. Recover the missing manifest, every figure matters. 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 <= 1785; 0 <= a[i] <= 1000000.

Example 1:

Input: 756 324872 580270 340509 766070 305171 965156 106925 318911 841191 164101 185004 219161 883642 808008 50011 516386 753537 909469 639673 950752 366588 620723 569078 46230 906172 137368 398705 741707 204874 588334 995083 158710 208069 205384 510039 704370 639850 897726 407656 810786 663811 144314 643849 608320 634984 360683 86112 338080 300280 768419 936076 632695 908224 939175 152878 732029 356102 202649 577138 736287 167764 488461 216547 673651 394151 34262 726101 602019 359416 102391 142901 48426 618301 226200 191866 647898 996359 64410 832853 359402 617591 401662 71273 963333 537298 808893 594812 411193 821066 716677 493072 104100 90355 790240 319000 634733 798855 992821 187858 673301 158601 94612 143258 281888 775926 844188 208528 496210 190752 751583 481354 479400 566342 399205 97920 9…
Output: 371374381

Example 2:

Input: 753 814939 779184 508729 178707 156278 246329 457921 9934 827755 178474 14706 379707 76609 63461 153699 973490 307407 415302 949867 192924 589462 127792 438833 74409 8426 2297 653216 37873 632280 178900 755977 958572 442559 810923 182430 612535 395127 23546 191494 37071 240465 778406 364273 445843 918558 864470 352222 969288 588542 236519 316652 363264 212825 431391 798989 35149 266570 735119 61098 211261 84341 656159 334183 670112 105946 601593 389101 720911 234115 621712 857614 77958 318491 676123 920345 150396 228866 298846 458895 128621 910482 690783 205599 757822 583422 798042 521524 48669 723859 889155 178351 404404 872447 554008 309203 943301 55402 584975 345035 730478 352750 90209 360270 779241 264714 258774 237378 923934 276529 622113 455969 187836 947784 873960 928730 486055 9912…
Output: 379821215

Example 3:

Input: 1113 327017 426945 680740 432448 387942 468097 14374 470399 525211 27394 269585 812155 592818 390323 488628 854962 185724 350975 311951 110810 534409 681720 424398 212091 661836 830450 3936 935153 292337 972863 644744 441241 548367 909280 416548 382984 281380 354555 940815 156556 730022 953436 720724 363882 383120 791589 298926 456503 518822 79416 833540 445083 201231 975545 687216 528879 481271 358833 703507 306689 779124 592648 487202 927678 595457 259915 460313 217963 961335 892748 43927 58699 260439 537364 289297 865960 122136 433293 245345 65824 804998 336066 766743 327699 869803 607321 196169 200928 795782 712091 966139 174702 672628 201455 512268 610638 605047 727308 643085 753998 326109 26295 35713 363141 1630 315843 855523 308334 265047 898422 173755 818295 484738 911960 34220 190…
Output: 534516812

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers at Glimmerfell - MEDIUM Coding Problem | CodeTikki