CT48745

The Rain Ledgers Beneath Tidewater

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the coastal hub of Tidewater close for winter, Rowena must finish the ribbons ledger - one figure at a time. 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 <= 3444; 0 <= a[i] <= 1000000.

Example 1:

Input: 140 935120 607564 765756 36745 500318 781201 476948 554470 30663 879064 110537 858360 106669 724177 72201 661080 191593 827446 94973 956893 934576 954117 399596 894689 707888 875596 771879 101833 348234 761856 539724 185491 202093 825614 781967 195704 865591 595604 574240 778197 853359 268260 987853 902644 133513 227548 198341 87750 523304 300191 179185 554988 253561 865856 468274 655640 17841 783386 120527 434945 911895 744312 681295 255358 453203 164805 650002 467992 346628 178116 299997 618969 606049 635046 815218 383009 987229 982770 446180 325650 456483 942179 964651 849569 138941 775858 696979 283590 857607 210018 986085 862932 835693 332090 752721 125903 622298 624272 99074 289455 728530 302123 563335 458862 925358 626311 592733 245843 708360 609969 622331 226550 475823 897967 9396 …
Output: 61355277

Example 2:

Input: 2779 384843 662264 27974 775430 608699 891934 744863 600631 107301 474945 649933 934107 382348 393065 476054 380019 143894 664898 878598 418200 932175 871718 817005 211336 917055 627180 567131 680007 296590 382247 459698 473114 101140 100052 266615 787971 227306 591264 12658 313795 161954 233144 527370 601885 63234 341192 228826 919595 616089 897608 137090 531891 661240 27016 651195 52406 376564 361559 398592 454117 19932 178987 967568 153636 349739 632288 510715 812362 855620 749137 627827 448038 337138 160985 632842 718122 952139 482017 244086 464167 373342 43499 64681 472166 107953 642854 977391 829706 946435 791035 989628 309183 95954 355516 138223 314846 800404 490692 698265 264780 531454 821260 387036 634094 632310 415000 82106 834032 645691 426247 987713 35102 631669 55896 635163 25…
Output: 1381667725

Example 3:

Input: 1399 639947 337643 289682 45604 396282 77481 64189 227691 332253 20070 444231 381617 915965 912959 562529 754565 594556 419761 22616 760849 108078 112832 354487 217309 133234 87295 504157 219613 147897 873065 572351 81819 398252 593630 139151 903825 801581 340189 395510 209545 202030 604944 657344 414164 930605 429598 216346 688817 295646 809986 305204 443963 793772 170956 243775 759582 365026 708375 588104 11496 289545 425285 549397 720366 58576 391109 901597 972144 534005 202465 933428 595082 101986 431647 25018 159778 326031 339255 218097 678847 285548 203675 720955 143767 983761 897463 326956 927054 188229 246418 360772 639259 10420 89714 4359 91475 586449 584036 941325 387392 954989 565526 643860 719634 381372 488194 414919 770263 961692 901629 544042 655819 269633 934575 302126 56562…
Output: 690444365

Constraints:

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

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