CT59818

Koda and the Sunlit panels

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The tallyman Koda has been asked to verify the ledger before the auditors arrive. On the desk lies a long table of panels readings. 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 <= 1205; 0 <= a[i] <= 1000.

Example 1:

Input: 152 288 152 129 763 854 84 315 943 916 453 865 67 979 932 218 243 254 925 641 739 924 904 70 210 209 435 252 104 596 575 376 765 997 114 672 872 721 893 394 144 397 194 680 150 330 386 463 81 169 857 260 943 124 38 42 497 12 533 90 168 910 293 67 615 990 277 311 312 455 137 352 39 771 448 298 666 710 309 200 48 728 968 547 98 715 922 30 517 663 720 848 663 981 710 737 782 519 18 982 278 260 765 549 898 240 544 276 883 177 310 71 932 161 604 202 999 182 989 329 118 537 564 520 63 736 127 830 961 759 604 776 690 5 724 767 638 278 561 49 728 960 922 948 664 118 136 942 455 880 232 379 563
Output: 69775

Example 2:

Input: 361 994 104 976 972 589 106 851 535 866 82 761 809 360 217 891 974 742 781 783 859 348 263 145 655 950 834 757 699 179 744 629 912 846 256 860 516 449 310 278 760 499 376 13 220 727 417 354 582 791 90 444 652 794 918 266 670 481 288 938 743 171 785 942 62 131 337 932 240 907 573 389 155 343 607 757 26 404 276 792 532 408 761 85 14 174 887 587 243 764 916 598 892 96 572 795 674 189 480 393 330 689 853 67 866 954 610 158 989 908 447 362 577 733 619 887 296 710 85 861 808 359 737 967 668 594 436 559 581 918 990 96 332 246 845 398 439 436 730 994 983 833 293 462 568 981 55 954 655 625 7 485 791 249 220 166 151 54 57 426 195 796 93 391 218 537 45 549 923 463 730 570 308 709 434 194 912 868 944 964 582 763 459 780 46 402 91 224 305 740 318 251 668 204 199 54 793 663 977 918 774 747 567 521 142 8…
Output: 167056

Example 3:

Input: 522 884 569 116 73 336 675 422 114 844 501 120 363 417 866 228 146 245 520 888 946 12 566 549 903 399 625 48 193 418 399 963 225 229 681 34 208 536 683 104 656 879 493 588 278 184 585 572 819 661 329 623 645 257 71 891 496 832 577 424 344 904 459 272 614 319 177 863 722 191 692 78 968 517 805 110 681 976 323 982 355 440 977 120 573 350 657 468 235 384 887 955 847 997 184 590 500 852 460 653 149 973 489 725 20 515 775 479 780 597 336 324 372 899 711 135 475 579 574 417 852 756 791 91 202 906 973 405 316 226 849 557 142 882 844 442 462 320 389 24 4 297 538 488 67 235 904 531 360 511 44 550 826 569 967 33 918 401 101 889 291 700 80 800 391 528 61 892 576 351 615 924 406 698 641 868 33 550 333 897 466 87 777 98 185 350 470 766 991 904 377 519 597 136 446 931 17 451 714 346 203 973 600 716 596 …
Output: 257845

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Koda and the Sunlit panels - MEDIUM Coding Problem | CodeTikki