CT46762

Cyrus and the Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the salmon ladder of Rushing Falls, Cyrus records each panels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1289; 0 <= a[i] <= 1000.

Example 1:

Input: 1195 237 478 252 228 791 311 223 511 388 704 979 443 924 227 292 779 135 892 417 236 329 6 387 223 59 845 13 842 309 616 959 150 642 983 337 311 885 931 758 666 283 228 732 2 674 129 554 424 253 424 194 323 988 964 406 239 491 227 438 744 943 814 340 702 398 900 858 569 322 97 577 799 80 223 189 276 688 793 305 733 785 430 332 809 999 754 278 893 658 200 741 14 975 120 544 320 394 359 485 304 86 400 551 846 370 650 20 826 862 509 385 56 817 481 270 188 374 560 58 736 794 359 881 840 855 634 951 569 770 253 676 492 71 372 605 22 575 197 62 868 510 803 560 540 415 676 393 577 233 950 594 416 980 419 864 805 842 172 699 818 742 78 170 230 576 1 501 898 773 63 742 421 36 463 248 922 493 316 47 40 775 689 290 947 148 389 889 802 522 36 859 264 78 128 187 896 131 903 928 858 555 660 53 632 270 5…
Output: 593493

Example 2:

Input: 127 307 666 790 764 96 766 982 4 369 867 821 613 294 216 682 967 237 181 116 349 4 486 135 839 948 40 792 217 659 613 84 109 723 526 440 103 889 123 485 287 697 542 152 829 298 422 887 97 189 513 896 53 708 430 335 965 8 457 132 293 158 971 34 725 757 931 15 238 53 651 299 315 703 769 550 75 944 510 439 648 591 676 79 956 690 959 379 597 578 552 705 974 216 923 0 446 64 927 727 9 423 416 690 504 968 343 615 322 353 622 383 140 179 730 518 550 727 321 588 796 811 950 733 668 428 735 501
Output: 56741

Example 3:

Input: 424 122 668 807 16 155 58 624 303 399 395 990 40 288 459 359 572 164 756 590 3 184 19 359 140 749 678 480 217 170 880 909 951 594 486 978 947 63 426 783 138 226 66 123 254 396 953 704 432 44 550 397 946 447 806 971 123 588 407 821 683 604 558 372 656 608 824 139 314 954 772 138 530 897 426 449 820 934 703 437 312 969 803 373 501 552 425 921 65 159 378 47 118 526 30 166 322 677 538 827 644 873 181 505 718 495 768 96 67 837 523 242 661 26 818 16 606 601 623 473 1000 518 810 878 975 566 416 222 800 783 765 593 296 517 349 446 680 263 356 360 642 111 982 203 403 750 446 954 860 338 39 24 866 313 124 274 887 356 592 543 858 750 708 304 57 898 344 22 735 963 969 668 421 915 305 444 610 468 118 633 754 426 588 669 437 600 619 497 940 626 862 347 910 556 973 440 70 735 87 916 516 279 845 41 29 157…
Output: 200220

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Cyrus and the Rain Ledgers - MEDIUM Coding Problem | CodeTikki