CT52745

Wamika's Ledger of panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Wamika the customs officer watches over the old quarter of Brasshaven's stores of panels. A careful computation stands between order and chaos. 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 <= 1879; 0 <= a[i] <= 1000.

Example 1:

Input: 935 281 962 782 773 815 618 251 495 800 746 545 184 460 500 519 177 613 49 467 398 552 432 908 129 580 236 389 806 40 665 254 575 999 815 414 537 495 295 918 544 61 197 232 591 444 887 812 112 712 403 925 717 131 563 219 385 111 737 513 535 847 345 247 240 410 508 467 587 845 112 743 273 35 339 486 22 557 560 186 184 830 338 308 528 888 138 165 533 120 666 343 87 946 883 443 221 297 831 119 344 941 833 640 974 517 698 147 571 965 885 713 317 98 484 313 660 555 254 180 157 447 344 82 609 466 370 699 189 999 981 437 280 973 711 560 270 382 82 660 946 784 249 504 115 120 925 542 145 375 83 166 349 688 343 582 321 994 656 926 385 810 535 987 208 381 447 312 364 14 503 23 180 644 120 190 47 586 775 128 714 265 419 880 968 495 182 344 15 613 241 107 683 373 368 644 675 334 914 499 520 235 777 36…
Output: 463144

Example 2:

Input: 805 973 703 767 730 772 927 647 204 778 604 24 0 820 533 961 766 311 638 329 206 634 2 870 4 886 248 395 16 223 582 733 79 748 547 211 484 344 41 331 737 162 183 703 831 488 758 363 775 294 389 94 740 281 163 253 2 605 362 987 592 590 876 618 435 534 895 984 261 828 953 294 272 512 27 75 30 919 589 741 79 645 877 612 33 712 312 580 233 467 44 778 393 512 111 805 659 971 334 308 106 298 185 604 149 187 616 538 976 242 375 514 297 240 760 717 19 663 593 838 749 612 319 901 482 751 643 913 28 767 0 608 572 363 965 864 529 70 49 515 531 496 540 817 848 903 169 302 473 758 664 734 772 444 140 386 979 980 275 950 435 991 690 971 855 265 951 155 887 471 949 712 213 968 792 243 991 752 34 512 302 115 494 291 120 538 706 224 233 553 447 842 798 440 96 366 38 122 937 2 172 727 19 576 99 272 299 420 …
Output: 389828

Example 3:

Input: 112 719 452 643 976 9 116 295 838 887 652 94 302 136 190 411 750 160 373 249 955 884 194 909 484 259 495 223 516 760 178 444 166 747 431 15 26 380 450 641 372 302 220 734 554 639 417 693 59 449 804 302 702 643 165 192 89 206 796 946 729 739 496 82 76 904 578 332 192 120 878 687 301 33 326 379 938 739 7 817 984 121 954 383 178 913 563 993 249 214 387 300 810 14 979 251 335 595 149 42 51 139 201 609 529 910 400 396 38 354 87 219 929
Output: 57467

Constraints:

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

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