CT56875

The Rain Ledgers at Masthead

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the galleon yard of Masthead, Urmila studies rows of stretches entries. One clean number will settle the guild's oldest argument. 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 <= 1020; 0 <= a[i] <= 1000.

Example 1:

Input: 587 191 725 187 543 353 227 362 165 28 130 532 123 920 678 55 738 417 598 455 446 397 976 961 577 696 209 953 610 460 65 897 767 180 147 636 238 914 351 993 853 901 718 757 589 952 482 69 19 859 611 19 235 64 587 193 230 570 645 340 654 82 509 793 127 996 230 370 821 916 911 541 791 808 860 436 466 426 722 632 422 521 961 827 103 265 87 513 901 844 965 865 119 379 565 146 340 939 764 976 356 551 856 903 574 108 668 389 218 897 538 788 612 824 75 490 418 116 501 90 640 383 311 105 292 603 954 908 516 703 1000 230 664 54 411 171 35 950 677 169 882 732 917 117 346 388 525 872 699 300 537 366 253 196 316 516 815 757 203 290 11 197 596 295 640 308 552 996 707 932 996 926 188 661 637 752 407 699 630 282 188 900 623 422 591 201 692 65 518 801 507 14 32 195 130 685 975 831 830 203 27 227 292 762 3…
Output: 275730

Example 2:

Input: 588 902 259 623 616 968 21 408 816 875 251 264 485 120 140 737 391 403 661 161 224 302 454 908 371 455 463 430 553 638 173 405 483 544 932 282 486 877 523 784 613 373 116 510 1000 263 691 334 709 759 700 431 156 221 208 344 857 339 763 818 727 136 935 222 219 36 532 838 564 87 541 950 931 233 513 525 378 650 742 197 754 491 659 649 691 590 667 682 761 24 770 338 117 438 455 581 433 934 592 664 888 555 928 989 959 717 984 486 241 24 672 619 573 762 299 851 389 389 965 949 1000 150 741 763 470 903 604 510 663 119 158 507 395 430 232 818 288 638 486 314 30 362 270 907 154 358 520 325 440 576 264 543 403 983 960 877 738 686 708 750 102 699 978 518 167 737 913 328 188 880 234 983 55 587 382 107 93 809 304 12 983 351 185 675 413 683 8 677 535 86 792 603 814 451 62 358 150 475 164 332 230 637 932…
Output: 281500

Example 3:

Input: 378 821 747 119 579 154 835 224 399 925 921 578 971 267 44 339 799 955 514 793 373 348 321 933 63 413 682 889 959 18 893 548 818 951 463 395 666 364 341 79 802 719 868 239 173 956 538 240 896 826 766 305 266 90 823 536 260 148 639 451 715 432 426 885 528 257 66 136 610 382 518 213 349 896 445 504 396 375 109 750 174 0 978 774 893 479 540 425 91 861 891 943 736 169 452 225 151 801 444 425 763 820 77 656 825 910 704 949 293 697 119 585 264 192 531 311 341 508 482 64 749 650 306 381 230 815 736 883 571 205 399 421 510 53 694 511 150 455 920 74 940 205 317 857 930 288 467 213 302 903 264 616 953 919 340 118 475 644 147 868 343 336 852 194 783 457 986 846 91 119 665 429 522 415 114 398 106 4 77 708 909 850 991 328 314 900 218 789 185 761 939 884 607 254 790 165 213 642 286 872 610 337 942 740 6…
Output: 177031

Constraints:

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

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