CT62480

The Rain Ledgers of the Pale segments

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Caravans arrive at the pine barrens of Needlepoint with crates of segments, and Vesper the cartographer must account for every last one. 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 <= 2829; 0 <= a[i] <= 1000.

Example 1:

Input: 1957 807 541 642 655 792 131 661 396 663 460 970 676 677 292 723 54 584 826 82 670 78 325 971 570 528 487 187 637 256 42 220 436 880 861 152 459 997 22 877 682 33 399 512 791 172 369 678 637 968 894 622 215 752 272 748 937 681 799 412 710 398 879 844 370 808 504 493 830 610 128 823 551 788 988 470 51 945 99 382 865 944 845 634 156 201 449 242 888 568 438 299 895 518 456 543 229 477 969 238 842 252 908 779 306 984 495 549 190 658 243 490 682 295 463 178 637 301 406 299 234 716 818 217 170 228 828 318 451 811 330 218 413 797 873 631 972 45 139 539 332 534 906 334 911 703 316 612 731 944 819 840 571 218 47 440 696 941 242 594 330 831 78 110 437 585 18 119 686 514 673 535 565 206 270 386 707 631 911 730 598 221 220 636 230 569 604 728 818 834 109 419 879 902 742 252 790 774 797 535 258 224 349…
Output: 941267

Example 2:

Input: 212 565 998 739 508 101 338 121 184 866 241 32 454 996 942 349 959 196 389 47 381 650 105 849 82 90 95 139 779 209 726 58 601 123 746 568 397 844 345 307 500 678 299 904 826 378 218 687 570 659 143 997 325 237 355 735 887 297 914 6 93 594 899 366 391 38 412 298 970 315 83 783 541 486 82 238 993 121 474 709 29 607 687 441 483 628 842 769 581 503 375 279 465 202 475 6 991 517 44 138 432 573 884 818 587 579 685 315 665 991 130 707 954 251 150 358 474 599 262 320 521 220 123 57 58 33 491 423 308 471 684 585 849 583 155 532 486 668 316 562 16 221 749 223 898 301 34 897 177 955 399 90 795 488 889 27 300 64 817 564 328 346 584 324 396 990 438 390 430 312 343 935 941 304 138 353 891 657 102 510 598 106 193 545 320 280 554 946 669 223 564 405 28 212 42 602 343 781 714 429 824 332 275 715 83 456 261…
Output: 105884

Example 3:

Input: 2442 654 179 746 680 784 139 100 913 761 200 918 455 874 183 505 872 576 60 184 537 314 853 807 32 55 504 75 652 862 833 928 53 602 434 679 365 997 261 563 931 107 860 43 522 159 257 323 505 429 687 60 218 745 288 643 933 897 679 662 147 419 529 503 353 825 456 586 931 253 181 654 55 139 83 562 843 453 402 985 660 121 204 257 262 929 780 604 679 858 553 52 431 151 948 512 594 445 161 878 884 978 972 677 841 685 14 519 102 628 129 319 782 376 244 573 4 578 168 687 353 79 643 643 804 592 29 428 68 226 220 516 971 141 532 75 230 815 608 175 239 460 622 401 889 808 469 781 101 87 539 123 636 284 365 746 980 767 140 832 766 409 505 978 901 711 888 982 244 963 905 857 408 998 43 133 595 467 883 736 978 207 720 388 29 161 901 949 674 699 50 863 208 927 781 260 120 398 2 107 780 384 670 300 908 55…
Output: 1214666

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Rain Ledgers of the Pale segments - MEDIUM Coding Problem | CodeTikki