CT56514

Cleo and the Scarlet segments

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the crane marshes of Stillwater, Cleo the customs officer keeps careful count of the segments. Fulfill a tricky customer order, 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 <= 3227; 0 <= a[i] <= 1000000000.

Example 1:

Input: 2890 166849186 234802117 719836158 719562508 507717649 725759748 694914348 312779590 585773301 291058411 966523322 902004154 600839682 835652341 444375777 768775709 142250902 27058383 87194172 648317032 660246465 555775990 227694704 922307876 5777036 85621937 523877909 866341089 208508673 620106994 527092282 738851088 527766063 848615839 795832874 273316732 341976283 97628858 755226550 956601447 166690660 352112167 526150084 684364213 615647727 888550730 164606217 624828360 707403532 26205031 905930216 262193842 98441218 550914345 949940325 531117278 271778180 104655144 788822091 267658561 997773443 814483994 720765399 852061361 768567336 904668667 956310685 4664939 565076256 465636544 985539342 609200278 842802717 735934317 143677927 987566123 482244554 738096472 212307012 154876104 10239…
Output: 1429055536558

Example 2:

Input: 2763 39939544 935923544 452082205 565688316 513336216 264381215 605018523 880503497 744523045 531416546 249754304 266420169 589169675 651681014 633585969 485401063 1347923 485908354 526012968 537485048 174454998 621748016 207387588 535404073 25993298 38969696 304110203 16930358 78895774 854651407 378522925 177572080 754159105 836513941 529321767 921342506 664810384 391219778 30676348 41810836 578406309 797912695 869153727 563119831 343444277 738813290 850516980 435202892 365159291 569889172 310372513 934665389 245667247 606909782 975783010 99292536 694008422 142580344 767052701 974660529 508904297 73706303 540326692 378657862 700823007 890638428 496881131 474509442 574975732 200923128 161581178 42254557 683948948 656187404 167757547 621002561 28690907 34191369 948459988 841065682 334583023…
Output: 1342911022637

Example 3:

Input: 1963 104974242 263546309 42007795 480781882 439459630 128450729 997719018 734255912 921169212 906451477 271092131 907723756 564642821 100315793 60552057 95753398 711500767 763670429 491677337 448711175 200888210 396440230 431964015 102742152 44475535 772926418 862204880 805517224 887470965 971586686 501913271 309845417 739186324 177296304 243581583 182052187 891412376 295189857 276165051 3948640 63041406 569439645 163041719 585163851 605389386 729503939 515217357 125929015 83460050 168026326 55447246 594268888 185840831 801005204 190605015 428230333 232030832 806511313 943868702 823348690 365781230 507815021 606140587 617078190 663776668 833192243 136957521 310619812 209170362 345983343 268370291 481558440 846051236 933883250 866071400 266976945 62572838 688761768 831295748 958618469 22874…
Output: 948342161681

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.