CT59569

Zia and the Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the willow walks of Reedmarsh, someone must prepare the expedition manifest. This year the task falls to Zia, armed only with the windows register. 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 <= 869; 0 <= a[i] <= 1000.

Example 1:

Input: 72 534 835 430 36 183 689 676 302 68 571 682 401 954 586 682 224 516 583 187 750 206 941 893 347 143 262 497 517 385 790 298 696 906 505 295 493 116 893 788 298 782 556 464 24 366 49 372 474 56 53 547 359 81 636 815 376 357 576 211 249 128 384 320 588 799 897 927 351 931 365 923 877
Output: 30571

Example 2:

Input: 861 569 10 279 226 686 712 715 103 639 311 389 608 261 462 608 6 845 64 13 685 901 396 527 576 38 608 743 588 402 895 875 19 860 905 296 167 122 838 380 260 432 754 301 817 287 220 703 431 615 895 894 989 966 133 894 203 52 975 662 822 36 21 857 985 563 546 953 354 289 628 264 572 595 608 924 47 622 874 541 245 104 741 327 462 985 825 511 98 374 420 744 603 991 444 66 439 788 482 722 1000 198 380 252 439 981 321 12 788 327 3 94 154 39 73 548 233 833 972 177 443 524 172 224 39 579 816 746 816 369 175 769 362 994 330 348 61 255 25 402 543 617 112 884 877 844 488 628 16 339 265 255 389 38 139 843 503 17 222 259 129 49 914 538 591 485 585 308 467 968 899 935 684 67 178 375 951 818 648 571 524 812 230 627 367 871 997 868 212 294 119 807 506 670 789 399 259 266 946 651 510 92 649 47 499 226 401 …
Output: 420048

Example 3:

Input: 628 178 606 885 726 662 101 817 624 575 36 81 68 912 834 605 659 789 683 407 739 409 438 291 982 439 515 650 196 729 267 404 437 33 591 325 658 687 1 61 112 523 665 901 155 564 634 2 470 802 647 205 691 613 848 986 73 896 414 489 250 577 485 105 829 629 54 975 233 15 861 539 709 78 593 246 556 386 599 874 823 555 230 9 744 688 232 130 937 778 334 716 222 814 657 872 189 55 629 217 282 654 30 939 126 148 830 348 672 303 196 504 697 721 37 880 243 584 819 4 498 54 250 122 971 518 328 96 606 118 877 971 204 341 762 658 500 902 326 121 456 640 174 445 163 511 11 455 444 831 807 477 582 376 736 412 155 749 32 559 836 812 341 79 277 636 893 331 599 41 4 636 779 322 75 867 989 528 286 961 246 628 33 838 456 721 439 575 972 311 117 204 605 759 230 684 218 559 311 924 6 289 14 531 428 840 116 178 6…
Output: 306111

Constraints:

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

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