CT38727

Innkeeper Counts the panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the temple city of Sunspire, Innkeeper 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 <= 1032; 0 <= a[i] <= 1000.

Example 1:

Input: 19 738 53 984 862 742 962 410 745 872 224 152 788 529 161 379 213 966 196 784
Output: 6792

Example 2:

Input: 884 918 262 124 467 864 764 746 773 262 659 765 860 377 876 777 520 867 943 756 762 144 550 508 768 701 966 659 246 607 697 213 324 467 241 538 151 309 676 56 463 352 161 338 701 641 680 636 853 534 977 453 644 121 768 936 52 536 234 974 291 744 654 673 758 343 298 247 335 60 21 396 165 462 641 665 90 458 963 30 878 926 460 245 280 28 593 62 218 869 12 809 40 367 1 583 379 383 240 871 983 847 829 419 615 195 559 520 325 262 273 882 700 324 393 962 857 684 351 972 879 839 911 487 574 464 472 335 702 116 703 346 939 891 722 327 73 758 942 612 70 919 777 467 239 785 429 209 720 229 971 925 893 691 121 91 463 981 655 896 300 874 745 593 784 873 978 232 216 448 540 411 363 891 18 946 466 866 917 27 183 544 324 324 970 214 287 711 416 192 930 713 190 517 444 57 644 420 782 294 847 372 993 993 95…
Output: 429200

Example 3:

Input: 25 910 791 212 240 918 261 37 318 40 998 529 879 503 955 886 28 802 220 216 107 705 17 166 275 161
Output: 8170

Constraints:

1 <= n <= 1032; 0 <= a[i] <= 1000.

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