CT59755

Nora's Wistful stretches

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

At the terraced vines of Grapehollow, Nora records each stretches 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 <= 2476; 0 <= a[i] <= 1000000.

Example 1:

Input: 1757 816375 477239 196081 669012 938404 561289 535724 133138 601974 666190 207686 801303 548796 910187 35060 120527 857619 26513 447821 782179 797356 981652 485060 613278 841182 284739 13968 518422 177239 923819 248877 795764 458934 503994 14324 968791 897373 958278 379033 297758 643160 343874 852171 799411 317242 268062 278567 504541 39635 824337 567785 98123 673584 265023 863954 790564 675928 688374 277237 713772 318565 756881 268762 439755 190691 23448 950642 546681 216058 380396 681794 18006 78250 150905 743555 561337 788088 277202 345306 635085 463825 910575 324032 3281 698155 957060 652398 44251 614322 764242 284162 825775 583542 614463 767576 227659 843247 561143 690666 626338 717708 926134 211818 158844 851780 241699 240571 373342 283100 365048 277912 835831 727244 249944 512406 90…
Output: 878009441

Example 2:

Input: 1995 286311 710928 798829 955775 391784 152546 538305 180532 729947 875103 864969 715780 606828 900542 160074 447035 234069 181931 398810 504096 412480 766048 458689 966678 358594 953546 852453 196468 329993 65433 92356 329754 627315 514939 321744 176959 926330 257132 47651 737867 360575 23240 523932 869871 496225 384913 844726 880668 87869 845243 196024 61950 8469 481564 196870 378578 285056 904898 416868 702683 685209 373794 458493 239069 10584 627472 422169 414741 556058 810772 338820 607420 267079 986465 177968 338417 423500 946758 983998 37347 296713 784349 246750 869205 727447 432178 926799 958354 88024 171624 850508 757114 217723 31496 54895 159665 376629 946796 466442 246019 460215 501755 673517 829275 420617 393731 358920 522139 386233 892821 497749 401834 982514 978074 285326 818…
Output: 981811383

Example 3:

Input: 1439 575006 501214 730257 463150 103111 275672 10069 508574 567582 486210 4540 77695 431089 279373 839368 953489 470166 547612 500833 35169 168825 71505 801058 39372 229797 129000 177816 925563 508067 754303 472527 141192 709801 56303 925753 314920 743238 26794 22469 522700 487238 232876 657129 270749 5808 616869 104767 209284 825894 299296 260464 828630 167978 897586 323150 562576 980262 740303 178279 970598 566760 693847 35381 702889 106577 970481 214129 411933 787437 235710 716169 580384 903615 348548 545742 865653 817774 452681 376814 890239 616864 787281 767126 500263 969684 690775 69119 541564 498179 169858 290295 319961 116078 799463 695708 350960 260854 805496 723490 375008 737195 895651 871534 798567 592295 233842 708594 205584 686322 534629 289369 53100 929215 294153 758313 27372…
Output: 701822753

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Nora's Wistful stretches - MEDIUM Coding Problem | CodeTikki