CT35874

The Northern Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the cinnabar mines of Vermilion, Ishaan records each panels in a worn leather ledger. The guild wants answers, not guesses. 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 <= 1094; 0 <= a[i] <= 1000000000.

Example 1:

Input: 192 805715662 605536911 40808143 988696489 649337659 322166832 135854755 529200503 978886784 867129830 87583900 14256968 487530604 800364947 583635699 10782738 645324976 613761454 888235666 661235274 112915109 190333165 797425457 602676171 171944545 379781014 607887823 924171175 773530899 753619329 258779374 526510285 181820731 693476846 937035380 664989817 776533684 825580221 899090407 315765055 390761073 746264797 477328972 479841693 743847977 251866639 548891131 561772053 616254366 642420107 90649296 263929340 479487690 951223983 354715318 9921469 107325858 211594082 444086789 180877186 481932985 950630352 801586344 501348279 324140449 223301354 679207170 408695660 809154452 60499926 357925686 155320632 883354332 663212154 717067291 238357216 295534792 129505007 573523161 853797469 2977…
Output: 92353140753

Example 2:

Input: 665 839459186 506084489 75916484 413257885 897284003 475706089 313684272 663877019 543765350 135134200 81661227 784299817 464173227 678846105 812286836 875763775 888857834 900794474 513655935 648487908 710454492 885385009 689559934 668999151 322418036 419490072 30226291 387751951 849866652 968333036 424897189 443449983 103190658 662610722 261185061 227812993 194348108 25348949 396935661 29803515 446438270 365814406 760069300 959326792 112068093 522247378 733427911 517472274 75505472 418233478 872077746 190800015 951246865 561023117 111906983 640866289 196377148 87943657 100944945 117737053 599509961 360434814 597665396 821154691 746258003 977125612 416830375 107083169 522186521 561802511 589403530 888658986 265406232 261605073 706175958 19163977 616085494 604014117 14259213 52270311 834647…
Output: 327386196757

Example 3:

Input: 1080 448807280 886060244 118297304 965514566 766047368 168223311 532766511 581430951 105859100 655938567 143000466 257813518 316316187 388068714 214062277 811352149 570560348 126717497 35149770 280432987 737621350 13873462 123498479 617455092 514340672 633108868 997079900 59501209 396183292 593316576 975699197 90052050 15175330 707621772 429239231 415395593 400147244 768621457 93695885 518497836 526554726 895371292 816821423 895710058 583347997 896316402 289345899 231718720 863478142 557546403 726307136 949418197 33927499 26274682 851546617 104777780 195240828 571325670 406089666 611676040 27694879 608191084 68026351 853079494 951193726 794629654 945032949 645856850 323511424 345954022 400585584 176969578 549043271 345266509 337397953 214848145 277037359 991602377 713871632 720999470 45331…
Output: 533339227144

Constraints:

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

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