CT41758

Uday Counts the windows

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the cotton rows of Whitewick, Uday studies rows of windows 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 <= 2370; 0 <= a[i] <= 1000000.

Example 1:

Input: 2002 897582 658917 661817 648453 333212 948678 329351 386176 497385 468693 649372 850811 960930 141058 143721 30208 110488 838832 706627 113239 782550 588637 287641 813809 741109 85970 143844 462166 881690 447307 899050 340810 456977 836901 829184 309076 565916 479647 110247 436717 22432 456725 389568 763673 113677 249854 636954 321525 194537 609627 710673 567240 495423 913610 927945 92733 244001 311149 301762 465899 878247 763274 385057 443097 41535 682775 25553 891503 442728 188800 856738 888020 106114 225208 143724 247504 865165 842481 498685 776042 533108 211231 867979 183323 94457 797420 415953 847 952467 979578 16832 344637 56030 578272 475451 553183 262070 394142 747676 835388 126549 524151 746154 160063 569736 344438 243396 408800 982158 657582 144138 397588 10081 673224 734426 641…
Output: 1006618253

Example 2:

Input: 551 932179 536443 164834 778744 805055 203730 323054 924056 308034 549680 440507 541425 346210 457566 836664 200542 12171 155180 634008 145566 333330 150707 318473 198326 338521 705817 386899 642878 850143 47312 590613 362526 185312 92321 346053 607233 304797 611055 142295 698981 284668 564182 729407 517449 317007 998779 596150 983364 893883 527793 554526 743353 626798 231204 713980 602883 146617 728300 22991 110062 538317 48860 829043 82708 26438 702037 332503 260548 760986 667279 240413 328823 535294 461914 347219 87325 932986 642366 52023 222013 338182 511533 3887 755523 245550 289204 168015 509172 878236 933387 481144 450000 402822 165037 255961 68125 142959 716054 975803 121076 497347 737740 69074 222115 394603 327705 470854 554839 624793 127266 908511 707289 209279 942900 379854 2904…
Output: 281258245

Example 3:

Input: 2158 733875 268248 425330 889119 961151 508293 515003 849684 193032 208572 455494 87064 25871 224084 134392 902099 236488 730551 8638 536773 754571 780766 167623 354831 585794 120792 801255 867192 377472 886584 237938 844759 568715 686021 505972 285433 637653 606802 760395 740277 758308 26813 89604 863776 170319 951649 241809 15700 140572 555162 654412 465037 317864 957408 804785 589600 875857 271127 841025 283441 429139 453807 430127 641804 790497 273964 400497 522354 536969 722439 563355 789080 771606 881737 750372 210010 309804 452603 652017 14484 617425 319703 97081 827716 809615 200125 737686 125938 737918 485382 956636 99656 933727 558571 365648 572873 882876 965 810541 651812 401840 670633 887017 787458 673440 876058 86525 903764 630405 431967 383696 792581 67597 592497 140308 17091…
Output: 1062873676

Constraints:

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

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