CT48722

Grey Counts the windows

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the shale slopes of Greystone, Grey studies rows of windows entries. One clean number will settle the guild's oldest argument. 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 <= 2825; 0 <= a[i] <= 1000000.

Example 1:

Input: 490 790350 162345 291347 319949 321977 480272 343636 623455 418353 855976 669675 530179 193362 683804 709289 617052 599248 620777 581697 818790 27576 396261 948134 938137 32736 345495 4873 945558 465964 493852 966219 754329 833447 388425 508105 238203 336273 259074 812879 663743 726910 912859 379981 877165 609201 988188 839295 835082 152680 574898 66584 602938 502512 754073 931605 685917 5545 608882 659710 369982 636894 514229 976227 935792 646532 108287 179120 405134 194307 565264 251128 348173 641001 170570 145443 74617 107438 459966 656283 525684 848480 883011 24931 50886 249808 601655 290345 122570 10245 590081 276463 931871 561036 158125 851922 794736 654608 538627 819755 146432 104249 636742 761329 7610 772519 404655 847969 399132 939507 559100 167473 388335 118877 188883 604081 1675…
Output: 242285827

Example 2:

Input: 2406 998059 971657 724412 315131 542584 414822 415335 776039 78770 723286 77590 32174 695943 302532 757827 336146 571681 616659 974747 731082 50590 739310 102477 160309 81475 255845 195079 225253 422714 703565 55357 865355 906772 945890 617415 8657 658237 110336 870195 747527 943852 88940 735844 754313 663471 250502 536827 616027 464697 482799 756760 824528 705235 407776 847303 359493 433418 888549 896774 580793 989065 884603 964367 139351 636181 933910 450679 20407 316168 83075 231162 164424 55675 848944 511805 914817 80665 370514 663489 241406 76696 81288 469446 999840 452377 421705 4154 105756 87299 116236 404116 843741 163697 157538 71269 936868 690589 346478 829242 514420 367052 331097 708295 816584 428930 954089 561496 872785 385002 934518 549797 667284 711426 393628 469021 462231 93…
Output: 1187387243

Example 3:

Input: 1549 777752 664732 915878 628205 960110 371535 458040 730859 9524 328607 541089 610248 785022 319072 777560 568255 901578 727683 942024 190016 344085 538125 696972 985535 775527 778604 588929 525647 422676 586210 264777 610402 454802 101201 822217 596234 807707 800715 666209 943923 553179 891370 362219 299189 143357 278227 558583 162860 31344 765660 480034 208623 842964 904567 967552 981596 733679 531388 614401 929232 946142 276470 267327 972741 638072 548369 805719 988773 218469 447748 604872 470745 442571 306322 398307 767818 678340 35684 270896 635595 850679 996113 154265 208249 94476 887519 541256 400552 272408 837709 348877 606897 67438 879843 147569 974915 162746 933086 690360 294610 356107 807026 150395 140044 464492 910440 590499 416784 687478 507133 306088 904692 294154 450232 618…
Output: 763549682

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Grey Counts the windows - MEDIUM Coding Problem | CodeTikki