CT41586

The Rain Ledgers Beneath Scrollkeep

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Admiral found an old ledger of panels in the ferry office attic at the archive halls of Scrollkeep. The margin notes pose a precise question. 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 <= 2617; 0 <= a[i] <= 1000.

Example 1:

Input: 838 519 45 715 594 996 397 242 12 386 459 119 603 856 838 794 57 792 30 759 633 563 440 795 610 596 251 632 759 163 181 228 644 464 725 954 185 738 667 628 756 230 598 728 941 118 181 994 818 962 737 487 586 768 791 580 1000 899 314 525 588 705 846 448 458 891 717 559 594 639 64 57 302 826 804 500 797 550 682 80 139 215 133 315 912 593 382 691 982 82 637 505 566 62 736 888 236 261 525 575 481 192 254 627 213 658 608 746 210 975 838 919 572 213 756 209 317 289 493 186 191 123 153 729 54 469 57 18 330 282 854 537 691 174 560 878 47 483 185 74 336 60 996 147 21 250 788 598 957 559 79 594 422 53 83 832 735 998 530 56 692 497 945 269 650 333 495 12 60 86 950 492 754 728 951 188 599 687 355 743 885 915 657 333 373 695 802 73 561 376 18 277 743 567 819 173 873 995 579 965 568 95 153 797 742 436 8…
Output: 403781

Example 2:

Input: 113 525 122 245 664 531 969 806 555 907 168 164 208 630 525 545 396 814 211 611 351 225 143 875 845 816 212 954 239 849 168 96 935 800 588 347 683 799 281 602 504 289 737 21 280 175 788 977 730 927 744 542 946 827 717 602 527 713 284 937 317 609 792 327 439 420 734 511 848 324 381 375 408 941 126 826 746 385 449 223 45 582 617 449 310 750 237 351 278 528 367 800 208 763 222 801 564 330 873 731 387 417 28 456 288 680 548 733 343 89 404 565 777 599
Output: 42430

Example 3:

Input: 2393 480 223 524 847 825 133 173 386 936 766 771 128 935 228 321 688 219 898 117 985 308 575 365 498 252 987 532 58 504 439 608 757 397 708 260 430 774 940 425 134 768 168 675 947 215 288 753 521 339 258 340 405 168 297 689 726 698 363 539 50 61 982 364 340 396 142 933 678 396 776 949 168 779 113 799 229 174 560 338 712 471 330 887 710 748 622 217 723 816 356 337 104 146 777 254 802 438 588 356 715 694 164 396 349 526 917 57 442 750 684 853 894 16 303 223 439 225 966 122 766 390 780 105 568 810 448 158 732 698 288 42 845 232 721 166 195 64 411 463 866 313 962 770 422 845 713 664 745 715 633 427 587 149 387 937 135 557 594 531 243 982 991 12 5 191 473 391 321 311 648 779 43 207 152 600 222 570 366 523 92 126 103 934 187 162 398 936 393 587 270 960 67 193 884 577 560 29 624 277 401 537 669 2…
Output: 1188236

Constraints:

1 <= n <= 2617; 0 <= a[i] <= 1000.

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