CT59664

Quartermaster and the Rain Ledgers

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the smokehouses of Brineport, Quartermaster records each windows 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 <= 2490; 0 <= a[i] <= 1000000.

Example 1:

Input: 1150 60486 930999 780858 567524 445948 799742 248637 803279 986668 723568 672851 553025 674420 148277 951632 791134 127959 33793 254883 557427 649926 259619 98632 706662 855071 237973 720490 394434 977095 668708 929173 526473 97717 277956 31615 381959 407917 391386 662123 316891 758615 750671 695852 463179 839471 302019 284540 396827 560708 683070 817587 351125 29698 141451 426256 216439 175050 143438 335382 345152 503521 460190 943754 232868 617543 792701 900582 445171 907490 941703 290618 386834 284610 62576 773056 248101 686758 344435 778717 71338 604595 452376 73853 521400 960223 93648 337026 785690 660847 788258 709800 224008 280730 893827 253279 642817 688762 543980 506770 390001 521952 828355 787091 329509 920310 925413 505117 110351 786193 835953 506569 141001 461064 286767 870663 …
Output: 567107941

Example 2:

Input: 2467 146128 585234 282885 377218 777040 376212 915748 163181 217608 772189 391616 776658 379679 65436 481963 432917 626497 664488 366948 345450 491321 189192 459336 334883 214167 232491 630937 54582 300068 301063 378781 63587 773543 536716 238951 653866 549836 661889 511964 897733 298341 993405 439087 852281 486863 607583 557181 207361 293483 244753 672227 329562 463010 889900 273178 274511 224493 299870 36064 492753 366536 736305 26784 118144 749296 339949 923622 289078 104671 406927 899134 441851 105981 602506 815885 151486 150780 976589 679256 93921 273149 41067 597543 318879 817949 450120 470291 953254 115413 450399 109742 781163 937534 477094 801068 251333 973712 833786 242100 755216 973643 612278 369235 770236 214608 705616 847026 35582 986566 898856 843245 626790 428886 713927 53897…
Output: 1202016818

Example 3:

Input: 370 187178 311094 137506 423669 672528 970969 298489 497406 343551 299271 117459 208742 511963 15314 383860 446934 259683 13260 783486 557031 920539 107735 448812 796240 399055 641264 750090 802215 590056 167564 209388 751281 814117 374187 479537 730433 48234 957688 901274 451024 228746 719578 104400 756845 18327 868418 523471 448981 817422 360034 221247 23885 80409 815768 56535 613602 994694 683173 780500 109876 170541 958813 861398 704777 530731 124576 984864 386198 944348 980320 670167 582184 208637 333889 364250 970994 267600 151298 267363 168408 145245 955506 542499 648460 497942 796315 404141 31269 57397 336364 80982 718099 828111 959220 5246 352114 738657 46323 839628 157961 595283 811950 480435 177186 143746 491811 378533 869550 456074 307207 49668 403982 905527 144241 274069 56432…
Output: 180283306

Constraints:

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

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