CT58675

Trader's Ledger of ribbons

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Morning light hits the ember dunes of Ashfall as Trader unrolls the day's manifest of ribbons. The tally will decide the next shipment. 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 <= 2631; 0 <= a[i] <= 1000000.

Example 1:

Input: 2090 663154 527349 746845 505719 504782 522187 499386 955510 69791 550640 587571 46953 646409 282076 862017 439695 640001 85077 453455 629041 884714 845405 670150 908569 394721 38976 852861 441764 399993 860929 363105 729581 51589 174910 733885 596172 414874 443144 610211 903756 770966 950477 513305 37808 657030 791773 795600 491600 657949 393569 492757 977609 308921 52069 661455 252120 516563 141272 215482 752431 934383 241507 118395 90145 768561 242386 324773 854970 882804 316705 583775 813600 563857 8956 863486 187321 514340 205453 379983 206929 576622 778852 847468 708018 828525 832450 286171 910809 904499 60875 920926 994959 830291 468539 68815 677961 132243 61607 690420 166829 699058 303409 878475 357081 804405 839779 393335 548835 654509 187765 504321 155647 562566 578082 298643 850…
Output: 1011207584

Example 2:

Input: 1572 289983 93430 747770 374876 469248 5585 451758 187018 187294 967563 857895 687683 39569 782523 381817 382710 803877 465875 736348 473060 382878 523802 999564 429 207590 981230 463979 379625 52013 904286 222349 650000 313546 332810 348284 947528 200113 146246 378747 414815 219529 41551 154619 516087 282065 221277 759517 786732 476483 193420 585844 949217 773027 852120 281249 830914 475519 979043 995360 590645 512521 318047 603224 746063 5845 747248 704247 230885 998657 405680 262639 960654 21508 235742 655927 220542 162260 205859 719425 617662 79090 195458 702876 397173 77940 551932 846722 260310 160029 474943 372698 418607 897998 322855 469199 162200 570632 627872 871060 899871 586397 896931 863784 644008 335074 138158 140935 636613 797780 628036 141242 380908 421815 740882 808438 6104…
Output: 759566490

Example 3:

Input: 2206 783361 23951 246114 752797 913316 428288 92756 614359 600612 10334 870528 269866 388959 380173 370258 295660 215445 230422 59798 780886 241181 982809 446858 974639 760681 889148 53102 311976 609698 766393 330750 742274 521506 70633 505307 79950 837478 944190 324599 123756 459060 684510 58873 422177 185391 949340 307345 468149 559043 414727 882569 220091 657321 519752 995373 330100 846081 254908 489222 397616 614481 688483 719362 547933 294773 157770 470878 890300 53168 48419 881717 341877 560310 291538 331098 222217 675119 351189 717610 368956 407930 687581 958165 129234 784056 436720 285531 70914 516465 76682 425757 431037 548457 983972 889965 444359 132768 864835 452726 897912 841462 351294 310410 288576 256551 529594 996035 368110 823157 236741 160003 59968 811047 637253 785195 272…
Output: 1076545392

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Trader's Ledger of ribbons - MEDIUM Coding Problem | CodeTikki