CT60732

Pia's ribbons Reckoning

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Before the gates of the salt flats of Palemere close for winter, Pia must finish the ribbons ledger - one figure at a time. 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 <= 2563; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1728 217614365 128220758 432718551 355980771 372792902 414723306 324795739 60789824 983625182 766712691 381161682 347647232 267781350 162733151 673943665 130977875 750674908 676666421 265267037 237480203 140083265 250639547 9230911 875968179 714842109 228796279 371332890 393892908 948167336 880268826 617851909 83298336 66302596 110833565 737251038 37760879 609247052 269162984 451393581 382119895 91043569 672667841 431492787 296699023 838483342 610548893 631370887 887967130 643254232 771199393 768744381 537415474 172348273 330975729 241618718 1376128 812038059 175876729 921430006 789346412 626628382 666049395 557104212 895606876 535843036 393922070 472130590 767832748 104098058 563341827 37862450 522116105 203124342 649163660 869513718 593016165 584221503 329557157 576961616 812451224 61315…
Output: 841622160624

Example 2:

Input: 489 341043758 553849121 533126147 11286935 688491046 239449640 303828653 905767014 135903829 597626258 602856146 169269414 207614259 76211354 572036364 3066949 494764562 690163581 991328728 63365870 682340889 115815459 47593440 459792752 600071453 311901308 945701295 716275188 516837337 644731391 440533740 970740245 12546001 587264441 410537640 516869212 749258344 906170449 817284415 124183059 212691953 247537811 682426613 981448774 225661027 240852103 199652629 13592065 344999562 163637834 179080659 536415402 319023305 129354675 665003516 903724883 683375122 471133955 612045520 486974778 864933755 617328988 812906001 285047142 809480914 909115883 405352184 860803082 683406785 858052751 284940142 122401166 685843627 366996327 581459164 722143914 540024965 258743905 305485679 385794908 2982…
Output: 229987955622

Example 3:

Input: 1035 362315536 948359723 193245537 30764853 432437943 215148178 58909423 560762062 470139212 686366182 74466824 408371952 14887459 345764181 850082939 863391478 798335877 907559700 445121191 707578109 187859378 824226862 469494349 223056077 1232718 283534655 759364198 643345960 380513270 995991344 410356763 671843588 270875844 525173348 121382336 480911705 942293676 353860927 882512560 159658224 274338840 910200646 263241528 399661842 593541694 365836053 92991819 249322476 833542686 570309788 719346339 146415310 107993610 421980730 465830490 50642248 576156486 148033093 40556190 364963666 712871978 294203944 606563153 382274400 95740203 267855955 40039403 627626286 239857136 88843765 441224169 731596597 919337157 916777775 83362982 45614493 156034718 961210108 699371365 532785847 826625099…
Output: 511598865385

Constraints:

1 <= n <= 2563; 0 <= a[i] <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Pia's ribbons Reckoning - MEDIUM Coding Problem | CodeTikki