CT49399

The Rain Ledgers Beneath Mirrormere

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the lakeside town of Mirrormere. Kavya spreads the windows records across the table and picks up a sharp pencil. 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 <= 2742; 0 <= a[i] <= 1000000.

Example 1:

Input: 1605 141909 16645 396079 242362 256432 686275 968868 109252 27611 700797 977256 171660 326915 900754 159095 197422 816183 507745 25356 641968 865238 808869 718088 263136 669877 753804 926481 192975 762853 256904 31088 701579 197969 39497 893720 416839 546867 624030 24563 692442 457532 897092 41226 207678 721221 22998 41387 903132 165472 909780 731139 855266 329015 628133 813755 372218 921278 736907 516253 952905 355865 358842 637399 627138 392537 688509 760349 254883 15696 421834 765057 133805 142272 356951 755753 325951 68600 531398 213332 198508 922645 792582 345712 578070 549333 669415 134931 176213 366104 537715 162338 844420 257491 432390 615985 347575 320040 976417 406559 866649 412299 692033 334555 186499 862273 535832 867029 721662 596069 575804 943729 541854 964877 90018 738051 71…
Output: 797634074

Example 2:

Input: 1863 566898 682835 239442 140624 557722 956431 693721 535696 600764 995162 453288 717996 333754 521685 997349 369887 94039 841492 876510 994775 883406 557323 688486 933604 842184 265415 977131 983824 716418 229226 660966 212561 739540 821300 511774 842126 193674 93219 682437 677467 621770 549567 225120 178482 594139 666685 632017 130021 639119 687 883959 536849 969298 471884 65082 167698 613891 248908 296684 870086 57152 768598 572187 181526 44483 746669 127580 810319 926702 923552 646131 650149 941252 910995 236039 297442 63514 794539 832458 528994 352199 567831 670447 614296 181499 977317 856206 273941 74492 676051 412604 708161 727335 856821 859296 317358 420994 704875 744932 822536 933527 346059 6686 745152 425870 600951 88335 46963 993712 769648 235973 41410 538768 656125 472158 43997…
Output: 922822321

Example 3:

Input: 1723 501274 1231 17586 908782 894809 22805 763923 762399 593946 52839 661486 780208 858348 65031 740066 805690 941115 161747 311757 279418 854085 914775 111075 628373 741202 964530 8286 478982 668611 276759 111963 556366 105496 832512 370945 49960 202791 133875 310583 553257 339758 847096 100066 585569 31115 527029 544699 63440 613894 829245 777270 808479 554503 921705 180909 475734 311199 820845 640770 160582 451330 253501 325230 152279 620686 812319 365936 351119 921928 933309 909382 370718 660834 895080 460585 676191 917798 281270 336050 539518 33828 74233 675857 150452 185246 868066 771537 931704 971781 794388 406011 719889 675161 441374 960989 178854 365020 776281 336196 408766 133601 474353 140722 100350 367052 524374 152714 853182 473728 637825 486957 272514 274157 442579 481 584918…
Output: 855088246

Constraints:

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

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