CT59760

Tara and the Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Tara the chronicler watches over the kelp forests of Tangledeep's stores of windows. A careful computation stands between order and chaos. 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 <= 1431; 0 <= a[i] <= 1000000000.

Example 1:

Input: 296 938018885 723301227 251887028 993132320 837737795 87008087 664049801 215348813 32677486 4726523 701763582 333071202 466273711 158543119 79619795 589471604 384196165 754272692 753686612 669778802 336068842 817358455 106678422 205516590 792170011 409428523 850529740 825044672 50137227 216422253 947717980 548346149 37143742 881869498 119546816 266041574 367831245 811589686 685113159 940448810 60023903 488295035 409308794 772651353 104655918 706221056 524538570 216431523 166591362 463995202 400594529 746159203 820963574 628905858 268347190 903474821 351838833 65729079 228318002 80684377 664352166 40284999 380193292 814222302 986632600 691241390 333345779 339902668 989406736 989638193 799308965 678124179 977466872 636196970 637380169 319052826 706765055 479300962 559160025 8018045 873041609…
Output: 146257905105

Example 2:

Input: 1398 241109457 601927521 597777069 80828730 677545768 432287897 535139438 33452525 783632823 216785839 163091511 526855156 367326648 682188583 268345981 501446920 653337886 23206883 140686690 915001550 686676268 303630178 728039724 495331693 194800229 631929056 633304517 41306088 909707560 449715700 226717264 366938179 620714579 50010837 929021070 716580055 793360095 357880311 148970823 598525425 130631213 967391098 547350939 560171578 740819587 957378642 768947270 840120803 506341878 748084675 25926990 606502053 995859481 620187817 505855062 668275021 38015357 309714914 762044818 48776828 117386978 677535013 829041590 224046676 824818166 311605517 461079584 250531559 592900487 928077258 272616919 138617664 600701877 44173589 419144221 173634700 983734429 813597245 65177713 124191995 48903…
Output: 698855981158

Example 3:

Input: 16 177488903 458967172 794183863 212900071 572925502 823539031 129715553 237082553 198339043 187340275 196575539 312566403 495566801 363158501 187197137 572140556
Output: 3644265352

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tara and the Rain Ledgers - MEDIUM Coding Problem | CodeTikki