CT49489

Omkar and the Copper panels

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the mangrove channels of Rootwater, Omkar studies rows of panels entries. One clean number will settle the guild's oldest argument. 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 <= 2988; 0 <= a[i] <= 1000000.

Example 1:

Input: 406 218688 906896 757431 609205 157494 592264 520862 768598 560460 114268 322537 608933 347987 990071 681988 352428 137966 840099 329751 72988 913239 378793 182331 814097 69877 574033 316782 389066 552197 76622 240331 904514 211143 929484 179212 301838 536311 595937 364811 685084 549455 633024 167958 923972 109454 419606 879709 211905 814657 88255 535784 589280 677384 701333 594741 471305 449243 527648 267001 415758 497391 659849 353845 663997 124140 869341 413393 805947 334436 636111 600534 777515 624332 641293 93675 37733 32484 650980 372239 626813 936665 522847 346644 582610 830202 551171 152177 924933 674263 595087 382874 185711 645137 57658 656749 216108 988514 305507 467899 461518 13294 25972 152757 811406 617007 348737 7241 407452 982729 770039 587080 658649 681391 459318 110162 145…
Output: 197181190

Example 2:

Input: 2956 72737 615807 332235 989250 21275 916636 263078 471551 672572 16478 905917 139869 674390 258968 543057 99757 375619 319221 626649 44149 807258 664039 522592 150459 486203 87758 696732 322813 448046 569216 667746 908135 334089 610885 298216 324569 244875 345698 116844 816603 595914 259716 955607 996416 399980 730128 57841 68107 564191 742514 957992 392674 998203 242039 976998 182533 321522 497368 47447 396338 405856 674845 116465 64376 617352 287172 537962 440056 908278 130938 599898 708659 504106 153166 970368 985331 757065 508756 508400 373218 942015 310616 219198 291991 760441 904317 843192 658224 975165 175809 121795 725834 56729 431826 403929 960605 887924 110743 483079 602495 863340 976514 236055 390925 278769 480603 745593 820462 803689 722054 688462 133664 618454 598231 486160 4…
Output: 1448124084

Example 3:

Input: 1109 101045 577860 480935 42364 703012 791757 120119 972336 735893 666576 295205 201655 937958 881379 281647 712131 290600 73623 174235 508226 356479 839314 260377 439172 166383 699708 724253 908992 658390 759215 379639 478517 28047 151368 653734 760111 890113 184441 663203 920232 549789 194111 273409 221942 697594 644870 433488 560837 396548 817208 269812 664035 46484 643982 605090 628307 260894 241406 111547 292926 565466 79980 306119 631793 46180 852077 19499 799641 29473 160204 191284 713897 103191 775104 124881 845836 506133 979044 806160 37337 252815 450868 57166 553004 101243 656292 604806 869820 443306 477903 791703 795771 251705 837300 150371 3515 156571 173205 24511 189384 107979 736413 229438 402187 961765 600808 156503 574891 889475 754682 212158 593267 410727 631680 432300 403…
Output: 538657335

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Omkar and the Copper panels - MEDIUM Coding Problem | CodeTikki