CT61393

The Sable Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the jade shrine of Serpentis, someone must plan the harvest festival. This year the task falls to Hestia, armed only with the windows register. 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 <= 1356; 0 <= a[i] <= 1000000.

Example 1:

Input: 114 785632 845496 219756 438198 714694 909442 69286 68847 304635 834612 963528 143042 908310 968407 971213 570771 943129 61629 151860 752638 470407 841627 833188 408237 237564 666700 181782 625549 708589 766109 443586 613965 458214 456425 4203 560696 944462 496706 330813 330940 661038 20656 326106 38158 996777 792339 904318 767616 327957 798578 518265 462449 962371 849498 19384 103676 489542 198785 191390 287509 310106 629757 341159 281971 913447 306000 712870 648864 458601 692055 236456 61270 90168 495052 871297 504546 448123 723254 326119 654138 878097 981592 5845 945490 736297 25600 866423 149284 192847 340346 574710 346960 805756 338432 483446 826579 875266 315883 123859 572826 360724 280467 693852 746476 885474 627735 279231 207420 459590 845527 495214 865313 609340 561848
Output: 47009900

Example 2:

Input: 148 965482 793646 697206 868144 46818 367236 597777 26985 303024 157016 706321 170431 396561 367512 824778 291153 281821 908116 70742 322645 668613 93948 981299 664611 97315 388350 207803 464244 234389 781436 147409 942854 604305 772519 698546 473889 888257 681344 937237 188433 340551 792080 227423 574938 330752 962055 814955 501001 961963 419608 802729 990535 237226 84554 151984 937894 659377 808065 104445 217121 564151 626210 157694 507036 783841 322034 173037 841218 425016 232633 254965 168274 7565 347874 973386 628813 857281 935550 453177 253818 835049 418661 258043 908692 862388 375034 421916 226929 254197 989557 90823 668368 323451 540296 437939 764573 345182 667699 540906 105049 435120 362518 140600 763033 594176 768173 793381 555864 523835 788668 260459 253581 175135 269652 600895 …
Output: 67208015

Example 3:

Input: 430 15979 54941 359301 455268 692838 625663 753219 519502 902146 835166 602755 393447 120402 787538 786501 848901 579745 391984 214832 580432 699991 166755 340848 894172 559578 921597 174843 828520 126356 397336 242348 818272 577266 391488 165768 488876 521327 870603 507202 145662 509780 240927 3694 584320 541916 72478 95130 923719 518818 508942 973979 117764 775237 136977 415239 413371 201766 833774 132220 795161 986190 420171 965234 719575 368211 754435 421208 561708 581461 620657 876494 88139 684850 407286 646049 746115 688476 904680 927283 202819 920068 236521 32281 696945 480699 20715 144844 732714 47001 51688 798585 880844 691938 720367 973945 947060 771570 278674 343494 256801 909267 31750 46355 361242 120910 331286 667268 963838 998201 497526 470768 991267 414841 412758 590920 7187…
Output: 204039187

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Sable Rain Ledgers - MEDIUM Coding Problem | CodeTikki