CT40779

The Rain Ledgers of Ashfall

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Wren found an old ledger of windows in the gallery attic at the ember dunes of Ashfall. 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 <= 2764; 0 <= a[i] <= 1000.

Example 1:

Input: 2690 857 922 190 745 452 913 891 271 145 667 94 152 919 614 494 184 694 29 785 898 722 145 495 162 46 592 703 304 684 985 430 665 570 266 891 675 912 93 314 314 38 740 413 916 382 141 630 432 494 495 557 840 639 106 616 20 208 277 538 893 564 885 675 584 343 742 73 83 482 264 320 94 379 906 874 757 347 660 930 252 771 291 757 441 816 642 331 28 890 736 925 283 39 246 835 349 428 836 458 748 953 380 727 228 847 549 405 943 237 796 768 333 476 147 110 559 289 8 742 740 1000 904 616 576 41 220 902 586 337 993 931 629 154 331 469 426 342 567 693 529 562 884 342 209 521 850 942 815 179 135 246 750 381 361 581 728 238 680 744 688 745 387 495 4 750 335 202 708 960 967 147 359 264 820 794 931 185 178 125 625 202 807 584 769 266 523 225 250 42 579 227 903 779 662 980 468 437 713 573 929 967 493 800…
Output: 1315488

Example 2:

Input: 966 108 67 16 114 54 249 552 762 135 868 228 631 88 237 865 432 250 781 735 653 545 738 535 320 14 112 68 271 960 796 548 29 823 525 4 213 758 746 606 227 624 815 409 566 261 925 888 235 413 12 758 372 147 632 405 150 209 616 499 145 662 753 732 755 734 294 869 983 590 504 206 950 777 972 168 50 670 849 399 51 817 192 415 296 51 641 126 864 605 22 372 493 71 54 225 646 823 276 26 300 387 477 524 325 454 261 771 639 459 265 926 34 830 301 311 981 121 28 978 8 71 756 675 29 770 910 734 187 879 868 196 854 453 683 386 527 817 805 13 832 641 707 15 898 361 852 879 318 101 48 981 858 549 156 679 997 164 971 929 828 93 947 720 765 216 697 968 920 678 366 160 868 290 279 982 294 993 308 380 599 379 918 954 249 121 481 234 650 822 709 652 844 146 502 498 161 314 124 383 912 414 423 105 664 649 783…
Output: 479481

Example 3:

Input: 6 854 319 835 519 169 358
Output: 705

Constraints:

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

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