CT59611

The Rain Ledgers at Verdantstep

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the bamboo terraces of Verdantstep, Leon the assayer keeps careful count of the segments. Document the rare sighting, 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 <= 1934; 0 <= a[i] <= 1000.

Example 1:

Input: 1696 555 489 1 776 380 611 570 237 918 704 401 586 663 866 281 281 342 431 826 183 124 778 490 575 804 713 303 206 332 782 894 551 163 796 782 637 22 905 210 530 166 568 610 188 908 501 4 775 981 690 411 565 310 907 890 556 774 874 103 511 675 344 920 663 288 426 168 314 56 151 931 50 310 707 994 42 945 673 7 452 850 207 571 582 677 721 457 550 873 775 119 994 954 236 159 750 792 582 601 567 409 702 669 597 251 712 58 18 932 773 111 196 33 539 985 222 259 104 193 504 403 427 930 68 48 528 888 140 398 205 953 838 382 236 584 882 983 193 23 71 365 90 149 598 480 477 769 208 430 473 305 802 68 990 948 344 118 715 963 296 502 660 54 146 582 788 615 557 508 464 821 550 322 242 618 604 345 943 108 260 730 882 142 810 32 888 844 634 404 443 877 200 994 520 654 99 351 278 380 419 549 218 301 384 6…
Output: 828305

Example 2:

Input: 4 924 256 989 447
Output: 668

Example 3:

Input: 1860 96 42 373 352 189 178 593 446 589 238 413 860 178 332 391 896 118 390 249 834 233 862 167 5 878 962 293 992 592 558 114 247 566 944 119 572 391 191 171 119 538 466 49 100 949 7 861 13 370 481 880 848 134 689 577 907 601 931 763 264 748 983 859 992 335 103 809 625 53 642 875 532 356 437 287 615 495 208 154 73 36 693 888 66 679 575 774 298 456 732 763 298 895 803 792 985 841 309 633 499 951 597 745 807 368 797 632 930 641 921 40 987 717 584 381 351 973 519 827 732 435 464 759 634 141 983 686 699 4 494 875 75 99 369 187 825 431 887 919 621 901 821 956 227 572 664 875 190 861 400 139 394 808 72 130 361 166 717 547 404 465 934 671 888 738 11 13 280 268 261 13 849 742 868 656 923 345 45 11 694 890 488 11 142 315 756 746 978 896 598 382 183 131 540 353 150 45 912 579 120 904 842 712 929 460 …
Output: 912847

Constraints:

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

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