CT55715

Jaya's Rain Ledgers Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the tundra station of Whitesnow with crates of ribbons, and Jaya the paymaster must account for every last one. 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 <= 2209; 0 <= a[i] <= 1000000.

Example 1:

Input: 710 232117 811685 181419 76427 165211 18670 785024 138755 544509 639430 796662 684338 691957 528605 861715 464599 599826 576489 914753 948796 899991 645764 458006 692380 226882 889018 150960 258974 778726 187063 700990 214420 524908 685891 940759 311665 362996 135913 760578 70155 32756 369430 735019 369386 784007 26419 76497 224471 920659 516121 499880 483026 19164 729953 265835 897774 756118 974574 506671 322646 141088 761558 754992 930758 664608 915464 822940 356806 96068 329351 584596 373404 339816 631490 20061 734723 292475 217849 255272 655334 921786 150867 646525 199166 736239 182169 445189 384034 197878 179138 851816 153420 807965 665994 24712 532342 686686 507029 435726 403666 924441 161419 650368 52626 668092 967954 181604 987929 500898 861576 528548 90554 96283 253956 930670 7493…
Output: 334711811

Example 2:

Input: 516 822767 260791 11337 690754 110702 841875 460825 266401 653564 942229 565223 240628 725639 358803 847052 174363 754742 773381 453554 634551 167534 198731 330965 725180 125626 944745 665716 444804 602590 113372 814138 420216 666332 828382 908909 280205 445808 778045 944226 893808 877677 743087 971721 649726 756208 479637 907138 465637 789910 638235 822801 916737 76420 270405 971012 14669 989114 864257 556255 540419 754193 98396 764216 415467 421439 524540 830809 700697 28712 135566 226231 105026 314341 914642 375694 292572 925667 446888 802699 883686 872999 787592 412372 622795 100627 547785 958319 23511 588807 35499 437960 729187 485319 741074 557133 770135 503767 787514 241345 976388 422681 80648 157448 726509 657296 728630 654613 52308 766228 522145 538280 363618 156706 919457 683139 …
Output: 235821914

Example 3:

Input: 1003 521046 565676 438406 169384 760697 107805 304758 55037 356904 963857 2010 478710 345429 382650 532240 522323 65309 922119 960791 179360 182165 328152 647455 326492 618910 172154 160739 371856 940483 425192 135631 686706 347843 135948 749793 764627 144141 824590 72718 517236 687561 708439 523347 544991 640336 59356 734180 245727 582065 401000 853909 821706 948045 255936 32966 4379 931803 662112 579807 838295 766542 309165 415115 539261 401334 100612 770924 479354 713710 853722 621618 618026 467064 765981 625176 154533 222400 850752 77288 541820 396910 98819 917807 581521 778423 889676 285648 437826 425903 120213 52273 355669 622039 800869 174862 617397 248010 770186 302517 399050 308148 722658 343615 852470 487589 371837 345094 219172 735835 563927 635341 682779 168300 87305 476618 464…
Output: 469341298

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jaya's Rain Ledgers Ledger - MEDIUM Coding Problem | CodeTikki