CT63492

Lunar ribbons Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the mushroom groves of Fungaldeep, Dorian records each ribbons 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 <= 1342; 0 <= a[i] <= 1000.

Example 1:

Input: 1017 527 334 442 920 978 319 462 83 423 405 91 804 495 233 91 294 272 62 666 313 177 189 257 620 316 342 198 701 413 261 394 938 489 251 617 179 596 330 672 26 706 249 547 111 254 174 724 218 49 784 690 189 93 647 615 953 425 432 327 486 946 232 0 967 804 482 899 84 953 712 543 233 92 239 500 584 754 532 706 799 385 453 756 296 508 106 641 100 936 88 319 196 495 415 5 52 663 15 487 610 682 612 248 720 690 310 434 549 722 398 368 616 168 773 225 811 109 463 168 671 786 840 235 435 252 973 134 285 459 587 294 497 406 380 830 618 298 623 670 0 984 876 606 707 253 964 493 269 222 965 986 909 287 928 592 603 520 113 898 114 394 520 70 616 381 374 808 557 696 196 107 310 896 21 45 608 186 638 64 392 439 303 28 334 970 834 72 766 921 780 782 401 715 418 805 845 374 852 742 395 75 531 310 349 769 …
Output: 490579

Example 2:

Input: 466 113 739 503 626 460 520 466 980 97 955 858 56 774 452 703 655 330 819 313 847 226 717 254 148 561 141 201 822 604 801 427 178 231 465 27 95 865 252 430 560 940 875 270 898 569 830 154 61 427 977 861 29 69 364 953 247 353 795 121 552 605 157 833 190 42 340 701 218 919 15 204 291 814 97 851 238 442 192 116 292 0 23 224 521 112 365 522 817 511 840 442 574 993 223 462 234 280 905 542 800 497 729 214 793 701 50 712 711 998 746 32 184 145 747 600 544 901 14 304 690 531 891 901 699 673 888 805 797 682 308 354 120 424 807 459 25 922 105 990 482 69 79 500 605 809 865 788 177 584 772 659 442 224 609 348 668 562 825 33 750 294 85 118 610 634 315 687 124 624 292 627 512 783 875 511 123 395 208 110 141 156 33 807 410 293 57 370 749 439 651 126 140 860 450 251 584 472 124 5 616 464 714 715 69 439 13…
Output: 219825

Example 3:

Input: 174 859 278 981 606 75 448 818 613 773 611 734 342 228 464 763 470 979 348 785 198 269 987 309 598 459 879 0 86 673 402 975 458 734 194 336 91 424 177 188 581 421 57 547 869 586 285 395 495 428 386 725 341 861 161 534 579 303 825 840 460 787 325 735 416 739 477 133 299 652 979 326 583 402 71 442 175 839 964 490 867 243 201 800 896 848 914 557 545 871 19 922 632 322 426 898 437 101 45 307 691 629 855 922 109 670 384 535 610 523 200 847 909 134 521 945 662 113 919 485 213 682 527 673 828 769 502 963 277 327 341 791 800 906 590 756 801 478 613 748 49 836 974 776 953 811 395 444 345 970 678 99 826 165 231 833 150 447 845 366 456 737 733 363 402 9 229 581 777 178 857 67 29 699 215
Output: 72814

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.