CT37008

The Marble scrolls of Hema

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the lakeside town of Mirrormere, Hema the chronicler keeps careful count of the scrolls. settle the inheritance fairly, every figure matters. 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 <= 3996; 0 <= a[i] <= 1000000000.

Example 1:

Input: 3157 895181575 857835095 233455888 678920320 942808455 401171153 683128366 135825385 835126790 731671264 544606197 570912713 864223265 11965785 840172107 774471698 996319409 205526820 536739445 270989079 598280649 3630248 908867897 903011313 979972163 15028975 795129674 457663049 964448489 996695099 110787152 606572022 312227840 700334550 147634192 575237262 830036374 355344288 775678798 434658496 914070261 239694926 826962623 758239767 675794906 39651447 850809251 881637194 31827270 10333579 979439319 341103808 115130940 199110123 677017198 4034658 376207565 787051170 712299471 166807560 961108531 790424870 460009227 824633277 992769550 56833274 190484159 622125347 849061777 381934965 776651651 898332148 12397278 479981523 189409491 809272351 175074493 184878183 871957820 378352861 388015…
Output: 1573644255116

Example 2:

Input: 1599 695208646 908496897 318283179 723853924 701234048 687936846 672393767 373993448 480305368 782208440 984045123 357520603 471973671 283799400 998493654 402682084 824447704 139095569 49283546 384309913 571099394 197594144 27391270 906200702 207359660 62626491 173062749 399684698 182340884 488722793 524589702 214891606 674821455 517178846 968221855 937052742 354657354 686805087 272176756 779382084 455393672 10820196 949249693 526214090 424507366 238906263 841427082 767292163 547412196 683388540 103855496 817111267 549418320 861171266 913625018 901440836 466444544 851015723 467169905 958816554 656642944 15147295 298657416 633843847 456157835 710817592 110743183 397697730 95799486 371319175 313118558 412681041 24926444 305184678 823512871 195328252 815840163 636244910 809494459 997638319 45…
Output: 785269475684

Example 3:

Input: 1378 874104694 526192970 39249536 787117588 268871316 742486585 950981901 743310444 532766006 732598867 975162887 677913543 657309320 739763191 754943 331764518 493009192 224979336 60530929 560455513 718415250 521966923 341788944 456721652 36914753 120365588 974307834 18084042 796332068 288644295 454149920 234000550 281697717 197918026 448056959 390272163 148854631 982745421 68368415 959416558 646101412 945962775 461662623 503299755 387078700 234228019 850458796 625743993 325044442 247452447 772437849 603532857 939976952 680841892 375032793 885612459 102221013 311628116 706723463 31224066 102823168 935057746 108750696 564200760 430455390 117131784 904134845 112304096 227696384 111787151 912178561 624431214 832734810 674637759 421410668 47677103 480382672 532197628 55527140 225911246 312719…
Output: 665552149277

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Marble scrolls of Hema - MEDIUM Coding Problem | CodeTikki