CT57150

Chavi Counts the panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the steppe camp of Horselord Plains, someone must file the annual report. This year the task falls to Chavi, armed only with the panels register. 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 <= 3669; 0 <= a[i] <= 1000.

Example 1:

Input: 3368 872 205 99 268 969 812 876 368 764 273 509 829 311 388 16 399 332 922 739 558 572 815 952 78 357 118 640 916 41 789 804 804 149 497 339 457 676 949 75 843 171 297 374 4 422 485 694 399 172 662 138 926 423 723 787 366 444 209 766 174 276 922 259 225 910 425 974 114 633 223 924 949 219 98 731 28 480 864 141 933 515 105 401 561 559 520 515 293 796 412 885 263 116 612 997 714 722 933 54 780 513 131 750 800 159 747 818 826 996 112 399 736 378 813 187 127 550 90 195 304 614 808 293 846 912 873 393 751 688 471 475 877 351 717 85 468 115 499 426 595 538 712 820 939 240 943 706 346 685 744 905 70 624 900 417 777 354 576 584 715 373 53 453 214 715 436 586 738 241 560 541 899 218 953 72 445 603 860 541 278 557 0 516 713 843 397 115 572 892 303 313 324 400 777 638 163 122 931 799 866 973 109 967 …
Output: 1688572

Example 2:

Input: 3329 483 708 521 9 438 643 761 712 279 690 174 769 258 56 348 923 539 653 458 138 738 17 827 782 725 313 119 294 223 891 812 745 9 721 948 68 892 793 279 448 88 972 546 430 813 716 36 860 347 600 331 177 840 488 318 930 961 935 368 953 577 499 363 906 402 865 605 275 350 949 77 471 459 358 904 397 279 992 784 161 200 209 723 532 104 612 706 624 810 852 715 554 280 936 205 271 355 296 350 901 568 970 746 977 716 281 897 24 662 86 162 551 468 388 743 901 0 402 290 705 572 567 32 851 146 136 300 178 872 955 680 864 469 807 629 774 81 57 842 660 711 427 677 348 406 822 912 82 284 821 261 637 973 882 18 205 143 410 149 523 71 612 67 657 395 886 31 538 79 407 472 35 807 1 182 188 383 716 297 347 172 199 6 338 653 168 889 387 292 886 423 632 803 228 614 993 294 433 161 69 913 535 281 647 823 182 …
Output: 1637618

Example 3:

Input: 621 731 492 387 17 677 167 561 480 649 385 223 708 183 850 763 149 498 579 426 782 429 985 642 162 734 238 618 897 525 22 347 253 855 94 290 199 286 13 102 804 700 702 554 516 74 995 412 918 721 369 936 125 622 895 516 14 467 628 99 588 267 856 981 204 212 535 103 415 241 459 473 816 324 72 322 512 928 533 974 222 23 408 863 952 811 830 410 870 161 206 908 985 754 679 537 993 728 958 859 978 249 146 3 149 364 535 23 518 309 820 364 744 769 820 512 19 576 410 481 146 38 252 408 57 824 585 405 511 549 302 341 345 193 969 487 224 966 527 491 274 998 808 467 259 543 161 407 141 174 220 150 926 392 569 934 671 593 50 341 953 901 541 137 478 639 292 61 139 231 737 24 102 41 606 606 786 367 979 662 286 731 837 950 796 309 857 154 486 15 466 401 551 905 977 68 7 869 849 995 302 816 976 594 461 253…
Output: 305212

Constraints:

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

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