CT45181

Asha's Brass Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the orchid house of Bloomglass, someone must reorganize the archive shelves. This year the task falls to Asha, armed only with the scrolls 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 <= 1601; 0 <= a[i] <= 1000.

Example 1:

Input: 1381 951 647 225 220 17 553 91 842 682 67 354 317 529 221 715 475 327 998 646 54 753 357 968 129 298 338 686 682 364 24 494 967 683 484 979 577 829 448 217 656 288 68 687 194 290 409 369 566 429 364 147 332 595 676 544 242 133 403 275 937 932 476 715 388 901 244 794 120 776 149 457 447 514 87 284 655 121 949 449 322 23 298 341 106 765 909 667 708 667 425 98 449 272 720 472 281 746 448 907 119 510 515 679 590 488 203 231 287 988 986 725 439 148 934 35 510 248 859 524 391 962 222 693 471 497 870 854 324 694 178 816 771 91 803 132 877 659 319 460 304 943 408 870 12 48 737 700 353 641 669 635 818 808 857 892 893 713 43 817 477 111 514 792 687 704 498 348 306 970 820 303 467 756 862 981 225 812 700 845 786 590 864 391 761 711 424 460 52 736 246 846 625 5 523 362 643 766 607 190 21 5 541 776 484…
Output: 688176

Example 2:

Input: 80 537 69 394 405 243 112 625 130 580 514 192 300 515 562 257 957 553 322 62 677 708 648 979 517 102 657 706 830 922 239 46 738 257 33 89 905 437 246 827 859 604 414 335 858 855 426 131 521 677 459 457 795 228 80 402 687 552 138 61 451 389 806 776 974 483 808 319 839 995 772 922 136 325 466 167 155 916 720 943 448
Output: 31212

Example 3:

Input: 564 456 926 187 657 134 76 520 712 241 656 746 589 760 67 763 956 72 313 503 358 302 995 67 188 813 468 486 752 497 407 303 763 459 459 638 859 88 598 941 600 262 374 254 113 413 56 409 996 85 124 739 956 776 783 612 924 891 344 708 822 665 170 612 86 322 572 512 264 629 707 527 16 619 851 5 18 433 341 95 766 663 245 2 23 660 489 145 244 314 582 715 785 298 807 610 518 548 989 943 456 498 484 464 360 1 68 608 52 393 954 644 225 287 956 57 527 85 927 617 62 304 542 287 514 509 962 127 804 182 859 122 424 690 502 759 168 937 362 417 125 423 456 300 109 759 56 605 194 346 535 235 189 89 779 523 5 721 269 801 479 515 494 997 618 103 754 952 798 662 877 311 580 470 681 369 633 922 565 534 684 557 191 893 449 671 938 201 812 480 463 417 456 555 984 645 278 616 523 484 864 638 864 372 201 214 63 …
Output: 277597

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Asha's Brass Ledger - MEDIUM Coding Problem | CodeTikki