CT37593

The Ancient Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the wheat plains of Amberfield, Marek records each panels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3945; 0 <= a[i] <= 1000000.

Example 1:

Input: 242 502223 984821 202203 565074 519705 790912 819492 521091 595666 379844 593646 270660 936105 562878 26026 969708 589333 910333 20607 466073 197380 397439 972790 573863 568994 161474 198584 933330 767301 921044 676244 560200 744896 537949 106896 837373 856088 344653 165529 334005 500389 432800 676330 185216 666785 1628 779556 831070 2371 558594 856236 638926 425835 427598 270558 58137 368198 482608 208117 982214 793470 38785 561294 922401 465203 748580 793665 563028 44495 770015 258243 465556 494120 92318 614983 800234 414921 38221 393573 659523 882068 835002 859539 447483 547199 731439 825727 968155 376701 912957 496438 988272 160701 351560 996959 310622 630104 8149 375375 875582 429862 785740 936851 684194 708783 695276 451527 376857 361121 12051 370122 21140 683605 80391 625049 19043 7…
Output: 109815600

Example 2:

Input: 1533 402465 696218 380734 78156 93651 692759 981490 364401 142967 947314 246206 947449 999637 377918 104401 324168 528183 410059 574675 440552 550280 361089 810996 884404 884377 295900 495536 60591 19835 847098 869798 345415 818505 722943 786848 806562 356772 22804 220813 63879 556026 597485 381490 210884 221170 677569 451493 114775 956971 426613 965327 967911 556872 625071 622434 534540 477779 215040 35873 844231 427614 849131 869631 642117 925068 371610 669746 498092 801383 935214 382306 925667 398892 888717 498876 589625 967871 981856 115895 565609 234299 798872 329514 633867 831472 717604 815674 903017 713707 381868 30928 425914 831904 829529 427043 644266 976137 178282 775588 651287 506320 56584 202285 534533 409031 130947 134645 831739 575029 869522 468108 470486 395784 151692 538611…
Output: 749297008

Example 3:

Input: 1214 163461 161174 98574 93271 49506 861801 244285 575094 106881 492568 359992 250565 537122 990849 994599 316644 114771 188827 990070 607030 110070 418162 790902 76826 413759 900988 147160 255150 26142 874298 99584 852917 851933 901897 282804 495708 289098 501850 61924 289373 830579 809069 735050 709879 813591 657223 660524 135134 609378 951647 711798 319169 469256 87202 483349 925323 241875 372160 355407 689858 596126 798181 500709 471115 710487 744784 814996 744233 556830 234133 545702 297085 561907 599342 44759 961680 954170 455584 851124 611049 767906 850035 901538 318324 883981 167550 665539 131639 852458 464396 602636 53228 520035 528176 529816 795316 711487 239982 876123 56266 711278 903979 826733 715545 132682 451298 297875 794174 472974 378357 727782 677603 943428 312740 379107 3…
Output: 592200448

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Ancient Rain Ledgers - MEDIUM Coding Problem | CodeTikki