CT60967

The panels at Glimmerfell

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the quartz ridge of Glimmerfell, Indu the clerk keeps careful count of the panels. Prove the quality of the harvest, 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 <= 2963; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2443 674820726 859447640 565541430 299911276 706602322 418205015 517421056 696470635 543933127 734535324 112017353 387709269 864891754 362367681 878510244 271552114 545199423 359188217 835401275 593014402 442526085 135463666 947280979 816722566 452249865 205775826 729058437 861607459 801051099 315381327 528128678 340077979 264222456 703271973 437360671 755085007 59244679 533946281 572460252 319912818 547447049 103563713 61415880 559226469 433906564 256663673 49967250 152550035 242159509 643217651 486735310 684201370 70101422 703036945 717965608 894556997 731633017 109380190 361103661 223180705 313592602 179575346 830917266 409818987 353442887 718833174 387110975 265143196 206435653 381372391 135116479 860381396 267556531 504127469 130801327 426971582 458033398 232462091 91277789 309914922 …
Output: 1176777132996

Example 2:

Input: 2547 562629277 207562991 380647039 748233586 744675705 182647885 695213044 666172754 431423874 292394087 421369459 388561661 292725119 807919196 525159302 731817350 35589649 81980483 423911363 548079109 168455350 128982399 500244632 604564159 836576501 428392784 731231917 905449367 896703799 547160703 817361424 781185950 131911803 765984988 354378805 24430058 458382901 451413249 64198850 899621744 994802583 557793361 446532114 191442447 225389156 689154814 389336368 301242284 305372103 674436370 709975694 349889399 931333266 888656059 28190540 736795212 632251948 21381510 308577558 831667292 502942881 493710411 983884753 425176553 557952748 284190655 355049816 142818118 993903166 900026842 597493483 22976634 505232328 290850599 410060108 989125154 506015270 891518325 247430505 326928128 87…
Output: 1234314272913

Example 3:

Input: 247 409659966 804663219 695265864 936757670 118602964 548813014 291294081 943366579 575175006 847723087 600224370 243745014 983078285 716342758 632623921 762679291 73820192 179935784 105760788 844521172 2568367 441391439 221102164 972128663 356374605 509708220 188253954 970014986 624225101 943819184 485510052 36715583 93689194 631689921 764977576 662193946 159906127 163254605 519278851 612770949 457936224 204253283 109978882 746740428 813904888 143144532 464825931 450939621 617363517 319567948 193216627 153044947 741023237 667893235 155268706 148138840 480968226 71303937 483158496 454362365 336013025 512097681 386316064 667542260 28564772 136942210 197814838 437983569 117091723 77548267 668907049 141463303 328626786 431666529 412732739 548457765 279862371 10797648 144562382 882270867 17100…
Output: 119483430920

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The panels at Glimmerfell - MEDIUM Coding Problem | CodeTikki