CT64342

Elowen and the Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The harbor bell rings at the old quarter of Brasshaven; Elowen weighs the day's scrolls manifests and starts the calculations. 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 <= 2809; 0 <= a[i] <= 1000.

Example 1:

Input: 240 85 380 946 458 253 125 378 913 579 953 98 325 60 596 319 540 660 956 863 540 931 481 306 261 963 326 13 270 161 617 332 390 987 472 549 761 38 489 194 734 408 916 290 924 569 383 854 775 368 187 984 830 4 754 350 173 560 867 586 256 696 925 123 143 199 772 705 267 83 971 763 425 909 393 545 431 991 378 455 607 121 857 248 703 232 26 747 914 374 289 912 466 769 729 79 326 884 612 870 194 830 94 417 382 722 510 0 524 178 115 930 757 901 338 423 894 682 204 588 11 771 632 59 111 840 235 465 197 712 803 654 994 708 707 879 498 131 183 969 825 768 143 477 721 484 543 484 873 504 813 680 72 531 266 333 933 732 526 431 566 507 727 898 795 594 379 234 591 259 987 225 452 44 491 427 612 101 170 30 869 410 219 665 590 433 468 645 878 934 930 761 519 723 199 977 266 275 375 826 532 140 901 653 56…
Output: 104333

Example 2:

Input: 1501 502 287 74 785 192 74 147 950 226 953 805 751 430 84 893 715 776 894 985 938 228 485 108 361 515 851 825 711 864 249 959 639 596 997 757 4 889 321 124 34 310 239 522 477 211 203 43 611 514 632 514 90 150 873 30 399 747 141 506 822 617 274 459 746 282 972 486 527 191 244 198 816 538 407 217 998 128 496 979 312 530 998 761 75 186 3 656 849 608 14 182 681 724 11 140 33 223 403 152 700 295 829 677 282 791 313 325 40 638 853 466 604 138 588 861 985 439 310 3 979 162 25 182 977 462 140 504 842 851 735 344 713 606 767 971 708 331 45 458 518 755 995 571 574 552 528 260 815 27 123 279 145 346 35 188 792 843 891 304 792 827 464 97 640 17 799 189 129 91 851 291 704 171 924 5 958 962 640 3 783 274 952 877 608 538 586 250 223 27 8 26 728 51 565 34 993 43 562 428 569 248 388 98 11 704 82 549 27 530…
Output: 733272

Example 3:

Input: 1645 165 185 871 724 737 371 534 477 25 391 721 57 382 491 377 106 904 752 769 377 424 649 816 981 897 841 393 975 413 383 321 503 22 426 598 760 44 87 617 289 277 423 480 594 220 684 278 534 738 968 55 416 532 723 680 418 462 823 240 396 583 728 670 634 632 578 165 328 290 297 167 537 163 317 823 84 907 133 467 893 706 556 302 505 161 581 882 741 221 289 51 553 751 405 31 91 269 709 866 795 615 938 763 501 93 277 445 474 471 441 979 764 809 82 312 518 159 881 283 574 933 459 43 499 136 671 383 646 294 264 384 935 131 178 79 432 34 184 282 506 137 922 503 41 941 339 604 61 862 492 898 462 383 916 776 221 264 745 510 915 870 631 93 721 997 12 444 581 213 131 508 484 114 599 124 153 678 455 27 431 932 816 366 650 397 353 27 317 346 712 839 981 920 671 727 18 573 449 454 164 520 587 766 476 5…
Output: 817275

Constraints:

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

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