CT59721

The Golden Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Tracker runs the loft at the copper works of Verdigris. Today the books show a list of segments, 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 <= 1759; 0 <= a[i] <= 1000000.

Example 1:

Input: 1527 722340 493174 624893 582602 141855 976351 105846 77801 7024 247363 151843 525063 443857 882696 217258 653297 272540 633360 157491 645293 35007 749222 605499 407100 772402 749211 502772 332299 619150 276251 766362 700407 272655 731276 395144 167766 887864 401663 225231 538411 514750 899143 430265 899775 298680 163912 663376 242887 100149 946141 473685 900851 209961 839412 987603 410851 466675 794691 378366 625499 627096 617788 883675 285184 67002 607240 553881 795397 283123 694514 806052 757113 629882 640377 394949 440875 406737 951499 674202 732825 144197 375576 124312 812745 422305 901009 259206 162646 694599 264717 849309 415823 209357 629528 727067 143908 797431 94476 798670 743846 487415 988805 707928 963145 127797 692586 840736 810948 948786 203624 174511 865520 918570 318077 517…
Output: 744986236

Example 2:

Input: 480 317479 662916 87065 970608 511499 164982 998983 628768 468211 126579 506607 619593 34633 258161 470926 816804 925460 937535 136009 988296 558903 400613 737876 374001 877028 725649 266877 740684 219699 602929 583813 348425 174628 150116 380459 195954 982272 507842 777783 359663 271535 606257 370768 821979 429225 474184 578444 831279 492428 451648 671025 391243 146139 673943 902098 125837 770934 914807 398745 437977 85944 328944 650756 176150 889317 99825 191481 147803 793155 491108 10355 783674 363513 963107 579958 906951 670242 208347 993102 927687 171466 675341 916825 474192 899703 639062 557020 842318 948976 700787 178914 527912 10357 414474 341982 582952 854561 509768 267787 748431 96677 332548 882734 690156 8061 36138 908025 38887 579960 635856 106785 819836 425750 784249 891004 46…
Output: 241132787

Example 3:

Input: 1686 217027 135171 860558 658432 489516 448671 843228 170820 745746 853662 809786 243803 816272 98790 839337 568227 722066 261981 572744 944646 907263 460621 466758 443654 139418 685378 185272 624575 995861 229380 419034 2481 303169 454031 895999 509065 631103 192486 114776 425872 343370 914972 680862 750810 960379 59695 292516 199966 809669 597976 8813 482376 559565 110777 791920 389438 597427 578124 625902 500766 37757 727981 73734 378098 996341 527312 713692 847282 219857 268794 420732 706255 417890 309154 45370 437063 72698 829502 56944 671872 764848 246300 315956 313215 736480 353357 212150 382406 605573 627143 924716 924263 4656 45442 495845 710872 454869 174265 864739 454918 816783 332776 843623 618588 821428 713395 977774 902979 639562 868196 507181 74451 207360 118940 523449 49421…
Output: 808789598

Constraints:

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

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