CT43560

Silas and the Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the mining town of Ironvein opens only for a perfect tally of windows. Silas means to find out. 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 <= 3952; 0 <= a[i] <= 1000000000.

Example 1:

Input: 1683 74406701 84644545 822626862 621040074 388871341 896522203 587824094 359888435 501822035 109035005 836357255 616200691 725765456 349846112 510208749 391583689 384151861 90316247 804399638 39921960 296267483 491476127 911384415 134426229 320077154 4258013 640295333 486531781 735984452 754535280 666089292 30972202 826149914 769415754 182396835 448308888 785572279 530943413 347349688 542213734 337535342 861984605 475713988 637945991 905756631 509716218 932531360 748604891 321636869 559239929 21810629 40738574 312623956 10671543 746498472 573820012 480438706 860723022 458501383 12947950 583864243 370848168 255617227 768694460 55826947 606996197 673745137 452577419 559488620 848399583 477970111 923910741 745171194 964963360 24399915 465219751 119234962 443905533 915537562 7581383 343589130 …
Output: 845683214460

Example 2:

Input: 385 403510958 661649789 195034657 836030760 883765340 438393625 143275150 636465802 316696272 712646325 493616533 559999455 407282520 13285987 822018818 672636807 351591780 30215240 386619581 840544658 221619016 41213429 261436386 421466980 249669023 145627969 967415235 558705338 249968973 321820447 342957439 997077324 360607048 666639018 544340418 437711269 209146247 191921386 307051302 188363529 684189948 270259969 487000446 655950085 244283942 771019914 858493808 614207076 232716978 497959096 928020040 934295665 457765786 255972929 716121786 611816565 280847627 952234394 901935735 199250351 696766154 995229305 648572510 443174943 17652132 827026917 373584589 668045336 233202925 548842278 591518544 332385975 469826110 654567084 923676803 321211358 619182485 362364139 127888743 721295684 …
Output: 188754519438

Example 3:

Input: 2782 224284911 98269603 280643445 651061890 244470475 10071069 414870651 743236416 109600833 616092452 504204387 722928744 734656988 219748102 424852140 377872956 141442759 949742053 713832821 168560315 957605086 78590556 542209048 791077017 315149634 247216215 948694181 371197516 467768441 357533662 333228779 46633150 916688906 701261558 949020249 578609395 246450331 490654790 642772805 460450684 840950992 285928066 889044840 553945286 406600029 758747711 416627333 686406515 854649636 429054933 457159157 514256809 49621081 419832094 288822044 389004474 257804756 388684855 127146107 512831794 98991201 794374830 189580403 879188655 350056516 429794944 487605272 525341451 229614198 682628117 695471840 48814998 235635721 465695905 102687948 754166205 860142561 765931066 286247218 872878893 33…
Output: 1375886939158

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Silas and the Rain Ledgers - MEDIUM Coding Problem | CodeTikki