CT51570

The Rain Ledgers of the Ruby panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Warden runs the kitchen at the canyon post of Redrock. Today the books show a list of panels, and the numbers must be worked out before sundown. 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 <= 2196; 0 <= a[i] <= 1000000.

Example 1:

Input: 204 772818 348885 510334 787392 349900 746968 494637 219702 752470 50356 965417 178133 253043 402719 224919 736601 379229 998672 791817 535162 863387 24017 589676 253520 362824 268778 54453 127808 393630 532141 341396 882526 537822 261494 312936 284119 313096 215886 10944 65818 171128 722028 587928 643116 588670 296169 355750 54166 958663 9693 62386 804918 405793 78003 272115 448609 637248 997252 560406 895051 478392 919761 666244 828955 699852 729946 779749 172612 307970 552544 966133 421566 436524 114366 944925 952838 511414 134410 220246 681422 887037 629361 826918 66952 706858 520050 135254 367985 945496 480582 570293 676564 701114 329223 317128 238792 4498 928125 431704 36219 310809 210332 59719 533798 728320 100437 477083 296093 371517 755044 222259 27694 19986 98899 569971 833877 70…
Output: 101480016

Example 2:

Input: 1617 769253 663338 745840 659493 333590 251000 381765 928432 592673 841770 747458 605924 916086 472839 939079 881424 790605 644225 883831 476103 639957 272219 289461 685665 117742 957793 940928 645106 44711 901334 293280 487552 561515 882212 485788 678462 31516 579479 352615 458568 474241 678184 228004 733518 536165 858647 382536 511903 743716 791267 331438 393887 710327 741099 161255 862633 550741 11881 333432 602289 133884 663732 289866 554876 723967 643892 765348 268872 867859 400514 113945 474621 197284 869319 585269 941576 909039 214666 167744 682589 19383 145420 892411 819704 390628 69494 144095 726195 709416 713083 877257 840582 530781 630314 275019 379580 850806 474455 378474 248657 662547 845443 11177 6116 16659 345126 343788 638715 138841 28919 53439 790342 367360 998657 222505 7…
Output: 822087684

Example 3:

Input: 1350 226329 693012 468044 951379 986998 268871 284208 60157 65188 976800 406538 44241 959405 929942 543459 357939 175099 457979 632743 913974 41459 952555 437290 334383 689691 423930 356628 888746 644786 104401 282423 295857 65075 893032 258859 471436 247988 630147 602433 521865 934266 830694 252487 67833 855758 331909 913445 6470 662009 979749 99766 378152 937462 232697 364711 735273 693681 946970 681442 452818 300688 242052 462963 265205 639579 166326 160425 95975 943804 7008 962868 189572 198559 776050 660378 313102 231721 252743 448117 58725 12801 504244 972080 960950 211421 806454 439520 2656 508109 436270 506457 224053 236656 898209 704101 398686 931924 410404 615258 732143 367312 450214 348505 822869 14228 410898 731333 393119 174614 357491 78915 746828 517803 512923 793205 492447 9…
Output: 663318232

Constraints:

1 <= n <= 2196; 0 <= a[i] <= 1000000.

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