CT60408

Admiral Counts the scrolls

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Deep in the caldera rim of Firewatch, Admiral studies rows of scrolls entries. One clean number will settle the guild's oldest argument. 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 <= 2236; 0 <= a[i] <= 1000000.

Example 1:

Input: 745 891599 152836 697830 505305 96048 879417 474595 873358 379127 493026 455944 291990 944748 7372 241656 50298 785246 118329 485453 801503 556608 145494 634950 330171 237999 831807 38554 702291 439743 801926 180912 789288 557961 47459 689766 39189 802964 736465 710706 31411 284316 45520 642675 918411 679873 525814 813703 574281 657482 414128 562225 685402 292721 323410 987965 133076 297511 352344 988993 586236 999014 124369 648765 223059 352933 605228 674044 422377 41045 646826 581052 675727 572899 929467 156755 857116 807972 628071 827706 13409 373045 808058 439926 774171 766590 349555 795425 244235 624236 310973 498457 649614 113621 48473 373430 179516 957861 873453 262024 566353 413202 266845 445487 672649 174113 1019 959582 264055 367258 485348 165814 805288 739467 202596 22165 988651…
Output: 352030419

Example 2:

Input: 883 577200 311181 103850 792163 761292 433743 911669 275799 834709 714147 322984 243132 830875 788219 721571 734215 485453 591951 904289 906167 916289 896515 646817 92071 585147 516610 748031 213666 517121 889869 515119 629355 709982 674415 489389 998466 552639 113182 642450 379208 140144 383030 957633 806135 209636 942660 495710 631467 710088 763315 324623 254175 345249 46256 302177 13180 191817 66272 759114 129421 804207 479390 590610 218957 986097 780502 327039 434416 526496 794836 271020 524582 135819 620390 445741 79878 777411 854236 509888 156260 294152 131082 85479 573393 646959 184865 350279 483141 73031 883013 445750 603306 10266 60958 46191 151709 433099 206671 866975 136963 578418 784319 460127 61784 330756 22553 737981 427879 861778 250630 676833 224252 430579 282053 446910 260…
Output: 422259421

Example 3:

Input: 1654 214098 118532 26168 486940 646889 366196 253900 899229 527287 427672 812359 220098 912614 273968 392639 527375 560342 675654 61368 277522 461175 819498 283943 225550 463187 967474 369357 697882 86159 328805 62848 484536 305972 78981 23022 590626 927080 438606 857935 224232 680226 426716 891417 142021 925037 984607 974711 76298 623362 499076 517411 392220 412851 826361 702375 319790 686785 786150 426317 148169 434285 214134 236856 636740 57565 524656 45826 797536 3104 751498 401938 591343 584457 814220 918230 832680 303720 639333 311345 30984 537777 129872 818112 737749 979080 898603 380788 966172 233059 337387 420840 504137 577197 170027 442682 246062 851585 205937 870984 290689 122393 79428 378066 959887 820985 819266 374372 397699 789378 780999 282754 367834 633197 565907 287628 154…
Output: 807319854

Constraints:

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

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