CT63041

Tailor's Twilight segments

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The council of the mushroom groves of Fungaldeep pays by the answer, and Tailor intends to earn it. First: the full register of segments. 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 <= 2351; 0 <= a[i] <= 1000000000.

Example 1:

Input: 509 500583245 181367904 144940360 948241026 848670964 867051484 889448197 107421300 157708704 908198035 647511658 990318221 534769081 47325383 818467354 751651989 759332837 239067455 888597128 475130569 318728486 134356014 137596814 696124610 490522229 503314255 763034196 18541573 850894776 123251102 399489881 571433064 7852693 756483112 232143381 88304958 502513044 310790358 136391448 780106959 479185782 777622373 623885289 391108565 887032723 526373266 373546968 315908864 41662694 977668730 420503506 469799177 49742023 58021511 819279848 101190718 227340793 384403226 793521827 719253021 928740136 499131790 849093567 898568084 719878275 235375511 859403138 648386902 239755514 360666615 875326567 511018778 949210226 840837781 502066780 352200459 549588763 627286789 348505181 463290571 8964…
Output: 248823626256

Example 2:

Input: 2288 660546735 297874753 103383493 775723991 816542868 353273916 967476560 414406966 252354485 491921129 79541540 10928146 115428958 924420184 748682549 414038377 859334973 782380141 590919097 807848142 960986459 206328518 521324228 573691765 155369837 612262778 528483772 180382888 346071910 880039655 136975344 378771432 319269897 292592788 792011274 823022083 208827227 572563842 67838778 822159943 489087248 500380824 488018965 927114730 748944135 837174344 691867436 248822576 187152722 431548696 845100683 733081117 801343775 183958907 924074772 270529833 177338786 534124858 774816458 581776672 916690030 949287148 388848882 767691272 951526504 771784682 897265241 316124457 17878028 350411829 326697693 827302058 229859103 265078188 924108265 993945833 534426294 699795922 931460286 313140020…
Output: 1112421006364

Example 3:

Input: 428 640776323 907654720 743392023 339347225 207019463 436505959 314977176 254908559 117711695 124876882 264933426 660372638 154152503 737340989 198594569 622569697 199655815 463646237 102578065 548332993 863402548 459779504 395679761 377028045 840306179 672928362 5855171 600921604 712698626 6545964 28387170 650137806 372593553 841712137 429158265 325279013 931826626 361295946 874001183 803634788 400775057 816228893 932976092 930693129 490371079 31193325 101560622 766039638 132208101 838018639 78511462 943001702 359475948 447702400 177323525 487259510 444034430 113018556 300581617 277662669 125515141 160357379 617045859 428895246 476073556 132701189 865845140 647259287 163283616 376088583 55032347 669862236 464406192 149457858 150003776 226763981 153918494 356264545 442498864 4642408 248142…
Output: 194760053116

Constraints:

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

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