CT52128

The Rain Ledgers Beneath Stillwater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the crane marshes of Stillwater pays by the answer, and Farmer intends to earn it. First: the full register of panels. 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 <= 1256; 0 <= a[i] <= 1000000000.

Example 1:

Input: 263 690477591 765686251 495175693 878010797 953521832 735183238 390275727 506598767 656613336 465393348 902809956 426058956 480750485 747605577 267892619 123604679 631321220 768427715 635566709 230851748 574287318 464926710 928607164 356692773 846971449 366993392 271616082 18452002 617593145 275116279 158479935 262926881 204708336 927070821 709335808 76430349 642677021 70221839 277840304 662733759 664745865 558120988 570264112 563284418 70778605 394754798 760691064 419043316 776569303 428027433 43256375 74480709 718906223 870137809 158152967 58750148 546575940 886475529 123862206 420723988 523665281 690728640 7308275 990139919 163115641 833620778 300395253 460896067 547495301 838756791 443437917 89845977 186644765 75859330 66510738 640645147 365952500 759332174 539026678 453003244 23589112…
Output: 126317886116

Example 2:

Input: 42 267423277 911945777 90487540 11214003 290162907 127064374 126836227 379256966 710231355 984602855 208698562 507087330 263984193 793652690 775693732 579046523 561292233 848901442 196363771 942515154 266350114 29801938 130705866 144450536 77951916 836064368 603258475 393029718 66978476 46822422 389604378 820216594 811521509 924235134 236585645 775361011 811717030 111078607 747897239 994712079 916974410 395934007
Output: 19300983256

Example 3:

Input: 496 574865478 737789699 964276932 939303902 530442091 18903674 649052936 66505625 621819496 291575861 19216423 26454244 46368121 81826797 398922865 58316053 270579748 777714278 594998519 962790087 810099509 899235281 325560821 58753274 470804651 762644886 894295523 619373015 489919136 874907766 297032684 535970417 18731172 827668630 560582356 383521881 159532756 60997986 61100690 994617035 174590881 597652177 424898868 954223295 429983902 668847874 407156286 558235362 778981287 334608738 193455238 546059352 951110263 726075586 149121789 441373939 408338808 443155802 177994777 138404536 263278149 335845113 585658900 28068171 418627265 508674700 614499571 578179149 957210322 198736154 968187581 180064471 598691867 36598255 708578197 689384620 868001208 985070601 991998688 781559014 831669993…
Output: 237969200364

Constraints:

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

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