CT43908

The Ashen Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Felix runs the stall at the garden city of Petalbrook. Today the books show a list of ribbons, and the numbers must be worked out before sundown. 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 <= 3728; 0 <= a[i] <= 1000.

Example 1:

Input: 3217 239 953 925 857 533 170 239 337 357 167 242 972 538 193 510 583 863 888 104 399 69 871 894 994 363 700 463 879 905 196 370 160 724 140 594 853 81 226 826 323 293 186 849 739 549 142 758 340 328 70 689 589 11 710 426 686 455 305 929 612 558 306 475 947 865 662 412 731 619 172 133 951 323 570 997 750 343 317 671 553 594 319 472 526 649 822 624 634 650 533 400 27 67 895 772 466 368 321 436 780 606 711 964 539 271 418 926 702 832 976 772 29 344 841 267 956 721 388 501 839 477 473 815 788 274 985 863 694 43 854 146 350 899 542 850 552 443 143 744 168 130 546 825 957 463 962 37 617 364 771 831 753 953 671 546 611 476 342 920 287 513 106 363 516 608 593 907 549 657 881 43 262 627 17 496 327 82 987 157 635 94 798 163 853 558 363 932 345 891 419 809 316 405 388 238 859 686 844 141 222 90 854 3…
Output: 1585645

Example 2:

Input: 2282 628 734 20 717 145 532 360 964 652 830 78 541 590 708 965 409 325 897 729 42 790 628 694 880 819 389 811 645 780 563 488 297 507 792 548 410 37 247 918 309 425 578 665 30 747 796 389 353 652 135 231 701 515 116 508 480 527 327 52 11 945 579 370 848 778 172 389 73 489 579 647 589 478 139 661 344 651 997 567 616 162 552 514 472 652 421 227 486 358 975 58 824 595 342 821 160 101 535 24 102 46 628 185 823 890 808 170 568 150 864 142 979 853 100 4 730 104 732 101 786 459 740 431 325 281 421 848 675 42 731 780 199 855 322 457 672 271 364 552 34 168 440 852 627 286 885 696 887 758 477 750 158 704 588 647 807 292 4 592 260 581 219 266 169 968 976 611 892 286 675 329 211 708 971 191 544 844 155 659 755 33 560 630 206 986 534 773 129 937 893 645 213 602 129 357 933 527 549 141 6 243 287 619 746…
Output: 1123878

Example 3:

Input: 16 833 536 33 929 580 770 635 124 247 635 164 181 920 975 929 534
Output: 5202

Constraints:

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

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