CT58077

Gino Counts the windows

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

In the honey farms of Buzzwell, Gino the inventory keeper keeps careful count of the windows. Schedule the next expedition, every figure matters. 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 <= 1785; 0 <= a[i] <= 1000000.

Example 1:

Input: 706 640287 743634 103523 49483 952648 265130 259771 468203 937756 854123 583886 202808 165398 131574 957186 301657 4886 539970 965606 913013 707410 443818 169415 390344 10733 986730 836358 291617 521790 997856 454505 9220 455543 118992 926664 809786 320746 649012 14702 105280 664218 975551 258617 34498 844309 753076 368928 882457 20140 373887 42298 304982 954206 104640 819660 264783 553730 643776 51473 114099 199744 515339 811089 126529 45092 847970 491713 70852 685219 718664 422311 746523 189121 966808 374152 557606 146718 714788 59634 488247 213540 628477 918779 78906 622899 269138 455671 231763 354033 610107 235705 886879 720860 986369 281533 165345 523663 895775 670258 415672 598605 326921 793095 252352 99218 411355 215657 673464 643873 507355 947511 49883 288192 606322 338213 169189 2…
Output: 346016981

Example 2:

Input: 471 279606 853975 425901 948473 145044 111623 865590 207184 816200 623945 676520 759420 214458 837087 84219 713491 723700 245606 892186 533886 5463 98283 421524 48703 397500 346016 794178 920726 529397 514539 2205 100319 181500 615056 777095 446048 949754 729014 351258 231009 439935 741469 106294 169313 166406 900122 412482 409969 691448 954675 877470 512345 839224 752231 828641 567958 145637 368481 678912 711116 551085 266136 46785 446500 296922 487339 971378 303966 653302 67578 324949 573343 123807 74677 48363 922748 562223 793502 336958 276711 179986 907924 976240 920722 367275 355638 730417 890021 773588 642655 12490 189657 657113 38141 295475 331756 237288 91533 306087 107128 778865 373737 354375 740843 994714 690891 538819 209920 467188 595019 396870 599521 418121 15188 597219 398197…
Output: 223177891

Example 3:

Input: 731 72032 55050 137147 92595 289535 503741 841655 866210 88701 740360 275018 761621 783404 465937 605273 235781 208672 933801 303976 873651 839808 796647 42903 400431 364080 412117 578807 801626 781188 922913 191274 630390 314345 243286 108291 935799 723344 397947 9837 922763 992198 982420 927357 678769 568626 534063 173351 989482 224202 410165 604494 62010 931607 850181 670973 166991 955990 557378 763003 815153 774431 349743 256345 444201 962530 998459 429601 383830 230154 184274 560122 363542 483044 312694 154100 748319 282186 32925 750104 355078 72864 446807 993081 769633 111019 137847 879484 623562 569341 886426 37221 176229 458822 740520 759944 442748 891655 922236 356343 304330 531405 577816 542493 668550 883016 715083 187667 973558 84505 464167 322055 48634 84728 978213 780021 56475…
Output: 350661600

Constraints:

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

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