CT59279

Neel's Shimmering Ledger

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

The log keeper Neel has been asked to plan the harvest festival. On the desk lies a long table of stretches readings. 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 <= 1564; 0 <= a[i] <= 1000000.

Example 1:

Input: 1453 334129 633130 128188 707840 291540 245880 391963 824896 812734 58316 906468 638650 210261 31222 699878 513046 421288 468414 590942 273531 510125 919011 631427 963453 830588 753341 155455 496972 323173 32296 169493 625277 139630 639101 146302 234350 682826 20564 705791 389266 987916 43903 280894 939754 227948 457603 77537 360843 672748 477223 818784 859461 14024 267253 191161 840404 801344 747148 637169 462153 555883 114551 955004 708552 971403 211802 722043 216911 966256 462167 886131 266194 468704 253779 250332 390823 403539 836941 628877 148884 351190 696204 310110 99992 820656 123832 771968 382409 957255 106253 192304 750580 241390 522427 123268 137595 180534 876296 352948 988810 808812 374264 691762 556292 826481 814773 180935 430712 672228 844381 830183 681852 124297 141625 12401…
Output: 720877149

Example 2:

Input: 75 771900 683524 780281 562895 955072 65109 512985 843197 301092 126544 334787 36877 499842 606543 778943 164781 849256 68882 552370 192599 551641 343084 675738 105206 603116 714871 475244 748782 688053 23293 502653 34743 805432 328758 808745 14562 65609 663162 482091 927715 105869 836593 600813 268758 683579 902519 638167 814167 288985 536823 750750 924823 334393 308758 472963 725657 46074 7358 394155 506619 283746 313373 4422 439076 736391 816971 946836 524186 513743 638517 245054 597344 216901 221287 764266
Output: 32217481

Example 3:

Input: 376 853954 710209 17361 54537 187890 969514 863317 509436 205216 641385 727167 7837 759432 984674 829425 631521 887170 677291 259728 767120 867067 80912 519047 29109 565809 611561 603195 976277 645652 525679 430150 169889 727851 302571 544621 68762 95353 732554 432797 177191 351714 513641 347703 754308 557400 936514 398818 86227 154158 767755 366429 623389 6756 693584 608338 964960 320315 541560 285199 750509 795120 669483 612879 235377 160968 732427 201485 481513 61684 191080 188353 26873 300264 315176 561670 404265 479212 83556 924561 622782 402467 226974 898716 573002 908488 963956 170669 270589 261921 712404 751761 495395 170245 995092 739653 650923 871787 517325 802978 222839 606085 161778 991899 912787 299812 302309 580209 763142 982027 370359 715931 2117 90095 518865 983064 747749 7…
Output: 181263801

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Neel's Shimmering Ledger - MEDIUM Coding Problem | CodeTikki