CT56623

The Rain Ledgers of the Coral panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the rookery of Crowhaven with crates of panels, and Milo the inventory keeper must account for every last one. 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 <= 2718; 0 <= a[i] <= 1000.

Example 1:

Input: 2580 621 557 123 917 211 48 622 184 822 680 509 644 981 660 875 559 164 174 189 85 369 181 728 345 251 499 952 78 227 509 93 981 37 633 879 589 730 142 258 947 970 588 992 154 697 468 483 449 262 327 74 505 920 70 506 932 320 467 398 275 589 4 197 251 222 570 820 473 404 526 478 835 801 231 656 269 989 722 980 677 406 443 473 127 274 203 848 786 371 572 13 328 544 612 414 238 36 113 570 33 756 583 919 262 550 675 75 921 936 615 852 754 416 531 792 69 290 598 881 682 555 287 627 659 621 637 983 990 111 953 750 180 816 512 162 786 888 358 714 35 812 698 175 997 629 925 671 155 384 762 576 51 133 492 542 729 243 580 3 817 282 679 654 865 143 63 834 711 97 98 570 327 616 591 754 551 664 65 814 16 736 831 893 935 559 934 377 258 552 708 351 710 571 632 505 712 420 550 185 119 986 748 628 923 15…
Output: 1266948

Example 2:

Input: 2552 968 803 591 312 153 362 826 301 418 418 751 569 22 409 93 194 603 255 24 416 105 385 377 221 125 429 347 801 133 836 30 755 919 262 203 226 927 2 975 157 206 468 459 187 175 825 365 683 883 867 875 545 306 664 248 684 266 273 419 73 673 758 460 769 164 808 967 355 768 262 504 930 593 578 383 591 258 91 955 398 842 453 673 764 659 74 348 500 643 719 905 614 822 40 121 46 906 211 641 233 699 356 790 66 76 373 103 321 54 275 685 374 449 331 727 37 507 966 608 453 640 637 890 638 96 686 254 368 616 671 755 27 221 281 169 948 422 848 745 435 426 275 199 707 846 773 20 939 935 60 86 255 518 18 354 153 637 441 732 233 661 791 289 993 968 863 548 277 310 471 953 339 816 162 423 842 377 718 994 473 807 346 976 580 823 592 724 242 334 672 612 129 351 566 22 912 799 714 565 208 629 990 818 24 93…
Output: 1276354

Example 3:

Input: 883 478 292 502 18 667 459 364 901 431 143 643 756 240 767 222 858 924 420 378 707 0 548 92 824 961 642 970 990 980 228 892 755 8 604 405 421 155 918 790 613 134 874 102 743 172 71 21 861 77 934 744 926 725 23 644 765 42 986 442 312 892 127 398 285 216 695 129 206 207 34 807 42 589 69 97 624 212 948 627 220 971 803 797 55 583 168 746 875 573 251 398 912 764 364 462 296 69 841 648 968 544 180 945 864 556 106 748 62 764 754 293 845 477 624 948 178 67 506 808 955 765 558 91 477 84 772 997 453 989 907 285 429 714 839 222 820 863 611 975 873 818 58 861 218 875 41 910 114 921 477 728 668 443 259 527 163 239 410 775 173 649 566 700 808 60 347 162 728 254 880 927 574 607 780 454 611 444 861 526 620 301 647 128 912 207 552 486 348 609 900 238 95 195 69 659 898 767 28 787 70 79 166 531 98 676 656 25…
Output: 421639

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers of the Coral panels - MEDIUM Coding Problem | CodeTikki