CT47960

Hugo and the Ashen panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Hugo inherited the studio at the monsoon port of Rainhaven along with its curious bookkeeping system for panels. Time to make sense of it. 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 <= 1040; 0 <= a[i] <= 1000000.

Example 1:

Input: 611 684334 541694 635838 908365 624898 163008 817521 729379 26965 325739 425320 147006 659969 197366 261701 849870 896962 79466 722471 634891 128178 189637 969869 240273 71899 890751 532966 321390 358403 542988 811880 355668 790722 384735 312584 834398 202835 922659 425979 406035 702101 557598 467193 373411 10950 885848 46735 931398 951878 229054 425504 931153 614219 382072 106138 629380 41624 742700 553839 531081 767358 443303 560771 52090 59799 920669 704204 538596 716360 712188 485359 457033 435067 719354 899678 506751 92001 646506 731421 226920 837256 400300 551200 100891 336645 103993 42534 68235 713676 963970 198535 262391 257153 82692 325848 413502 955901 895766 292640 971410 841276 502615 451879 31901 660162 850727 510783 88587 306554 675574 74642 272291 286101 350525 789007 731921…
Output: 290083982

Example 2:

Input: 754 504004 366397 640419 829159 503894 210599 244821 157528 365885 522919 823114 484111 130828 230015 33741 94445 145525 166322 715082 889133 307103 527995 325273 693380 910752 479158 879049 267348 288726 771690 440779 917574 143182 81587 93442 850204 587643 473173 135622 141595 689649 257895 712067 663881 672978 246363 486033 589879 919778 266490 261603 717265 149920 416266 897689 943928 414919 524949 386921 882610 797008 815033 451653 271554 265881 69419 272487 133240 316997 898755 678128 89487 363864 313799 353459 538499 848546 896438 192054 344917 467722 536025 338568 532737 127626 250799 35922 668281 95889 560457 38509 345410 145431 618018 273430 172988 665866 820537 555625 245203 731552 564326 738326 504543 556284 266240 272929 788317 550994 626715 771150 61484 385980 65704 717927 72…
Output: 364553435

Example 3:

Input: 212 846165 71038 199240 669103 537514 963628 929978 348957 143944 473106 33621 463640 9492 984942 832729 168042 614298 745693 442116 725799 694780 406019 241897 318112 849622 740568 835740 623038 298453 943378 920790 631407 864045 483721 999955 417872 649386 48778 22066 242425 807942 781473 326384 141886 554971 311792 707068 469557 103394 96426 877409 493385 428224 559897 664954 972475 103493 925460 265091 790199 911575 577120 899968 736011 967018 773251 596750 288888 534322 34994 780389 126366 349036 144094 624829 334005 405061 80488 127840 230199 250975 691625 822804 376375 667299 758015 224048 595153 861966 426105 150019 576603 532379 934714 834369 726806 758418 882981 284775 219405 115575 431537 784876 260710 548662 147279 446268 570867 177487 4812 957226 761201 138349 472870 911971 77…
Output: 100770870

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Hugo and the Ashen panels - MEDIUM Coding Problem | CodeTikki