CT55818

The stretches at Bramblecourt

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the thorn maze of Bramblecourt as Rohan unrolls the day's manifest of stretches. The tally will decide the next shipment. 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 <= 3483; 0 <= a[i] <= 1000000000.

Example 1:

Input: 896 704869390 770313 934550459 124681583 432416886 418145125 421150102 81406327 303599821 786897771 430093724 379506515 870295734 480755985 280194300 461022944 297574110 451061641 590854779 171880894 712381109 455114914 650558217 766006255 112783655 195540995 611047173 459279241 980464623 961089305 636723311 734020888 298445779 398678686 886751765 633232586 497519094 112785316 622635918 234499019 456621484 331008910 70663103 650905818 447659462 848725675 433998370 282169923 442944727 129573778 223732467 213422527 273625977 822106477 171602171 617916770 346190715 38679519 644689230 137806343 616621854 114474618 639655706 859826067 863297850 274245714 322558163 349152628 510269326 901333621 355919145 761473022 217577615 939336625 497809478 555474476 448991496 543838058 968677571 173713367 47…
Output: 448044492816

Example 2:

Input: 1145 853807236 850090137 673260615 772488375 793640269 112160705 61980188 744166109 869065697 87878960 751015848 532469690 83309791 281294103 742201991 860066010 522063427 692235183 166617761 20161204 522126228 250200313 119330944 416758008 246933699 900473059 882102001 472245244 515474818 413101016 214163342 768145064 281911195 449674233 612400228 744368071 851867817 709919680 146755087 900021753 89457999 906912763 30551784 69831513 560058245 984219603 746637418 341892387 676038962 126935706 678620943 277025910 544611560 52054785 80158497 621707272 491099543 911122259 14301788 321274960 35372415 692835911 450304235 913125850 32800727 302656419 704303203 244963302 672814509 583922564 513228035 289983512 825330543 537218878 417706599 189584628 568195562 527135457 431887801 189158523 4388013…
Output: 554568627749

Example 3:

Input: 748 347307612 902856818 262835891 88877445 722594567 622681535 839157044 939354067 286871650 206537009 701309237 187952222 55795807 626645791 667395205 223067091 601993594 690546144 238657591 874064485 264179215 250234630 102142066 980582880 19910315 379767427 267317709 276804025 427362079 946380409 326276799 717563583 84715464 326944863 993051506 987342970 934066224 103337681 138578699 255232386 83993245 245129707 386768901 314525493 903902735 297688133 654929950 124532835 35417752 375988330 719281579 813938953 340081311 546388107 498755157 383668022 56453535 978098406 548943444 82564558 143794182 89415094 966622281 747109178 728999018 427400188 389655610 409884839 928368989 35173882 486271578 501847227 105829953 69392582 453173376 721184481 941533027 830084979 445442638 182624673 6557421…
Output: 377866539975

Constraints:

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

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