CT41024

Brewer's Rain Ledgers Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Brewer found an old ledger of panels in the observatory attic at the ember mines of Cindercrag. The margin notes pose a precise question. 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 <= 3649; 0 <= a[i] <= 1000.

Example 1:

Input: 3175 625 249 689 800 464 803 669 469 934 272 531 376 104 137 141 466 837 883 974 803 691 302 218 455 646 508 545 482 222 943 80 359 799 1 753 273 404 636 856 393 675 649 636 575 34 136 931 536 959 539 46 287 452 134 501 314 901 299 905 803 767 211 238 266 376 557 951 248 508 798 923 365 508 354 97 914 149 336 101 385 391 841 442 439 223 802 795 371 467 759 179 190 638 764 454 746 588 803 771 253 293 598 336 509 357 306 521 422 775 101 303 378 757 938 196 558 853 254 798 793 582 576 450 176 237 588 901 316 935 426 764 830 586 383 954 99 178 32 187 253 866 57 696 691 42 776 239 846 699 335 185 863 750 186 157 689 293 819 674 520 973 332 762 444 936 92 37 267 797 0 534 459 344 6 132 59 515 827 426 393 449 621 347 145 723 141 200 146 866 122 809 886 612 927 911 110 880 82 97 522 851 573 781 48…
Output: 1564859

Example 2:

Input: 1749 296 523 593 197 943 479 630 666 430 890 872 328 836 494 917 199 534 654 837 642 268 866 615 607 127 608 206 657 484 225 538 410 76 364 66 30 975 740 492 924 471 647 533 129 297 19 2 442 625 593 64 655 692 153 407 966 737 2 691 349 391 2 859 724 112 800 859 549 589 770 630 896 765 457 288 634 917 172 968 67 414 486 475 795 412 585 940 47 839 528 218 924 281 848 185 620 782 521 924 460 404 126 251 398 274 76 217 723 538 453 997 553 277 325 86 732 235 666 508 858 553 235 534 983 548 416 297 259 740 766 386 112 979 691 153 56 418 484 334 949 914 86 331 316 467 699 780 487 490 574 528 445 650 816 838 928 647 112 466 377 536 424 388 379 17 627 984 28 680 542 192 211 796 924 877 46 947 57 424 672 358 343 547 28 746 491 434 772 222 949 483 452 923 300 63 131 174 976 537 996 431 322 641 795 14…
Output: 849735

Example 3:

Input: 9 253 302 739 248 76 511 404 821 36
Output: 1717

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Brewer's Rain Ledgers Ledger - MEDIUM Coding Problem | CodeTikki