CT55287

Brevin Counts the windows

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the salt flats of Palemere, Brevin the dispatch writer keeps careful count of the windows. Map a faster supply route, 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 <= 3904; 0 <= a[i] <= 1000000.

Example 1:

Input: 2790 172901 432775 584698 925580 778788 451784 634234 120468 469246 178200 541171 376108 255075 94633 197306 684479 385227 877737 221153 389388 831443 962577 666935 698228 659743 974926 676931 674529 955817 3872 297675 942549 371635 920037 230369 977764 233218 912057 90667 343402 501576 376580 601857 382052 204707 462621 800001 71639 949394 958791 867182 652017 402610 386772 691561 338461 50827 985526 379471 918973 64736 564704 640358 533969 180506 306207 154105 970244 465674 573994 275767 410814 408571 670962 216523 288551 545774 64016 950732 837700 507207 934285 839740 376220 531913 457640 972273 79094 976413 976801 202683 392269 147662 993547 953283 234683 753500 672055 843054 513549 443788 845064 811923 157630 820374 758948 585224 679904 4904 237107 472419 516751 871608 58555 109667 91…
Output: 1379985397

Example 2:

Input: 1281 593284 461438 377157 730384 560760 978499 84170 992857 328305 108923 602650 765237 366999 266905 477150 648443 650750 381493 541114 571543 284328 351902 441380 659840 397333 279291 7952 677333 848557 870754 150603 526179 307095 918213 11185 75215 51777 540610 745787 994734 427094 267134 357342 6432 751594 398173 583677 545232 11796 757759 693397 149472 631941 44211 924357 13798 159456 330476 443142 309888 117885 375427 56427 969011 748663 640574 219160 920136 540528 903425 315003 737481 484799 459148 430733 187384 169191 715519 237648 35598 935139 254279 902754 930285 373450 485371 874114 333504 880265 631587 677002 39645 660588 339759 704450 532361 470500 772293 640537 552222 501166 931966 727935 668873 328351 346902 91052 452758 960490 622406 480477 294138 262436 434526 305387 21220…
Output: 648507099

Example 3:

Input: 3153 937277 110567 729980 588919 556086 865984 938345 321292 943675 743717 745118 575483 189982 67366 66069 875072 907819 484638 84156 446760 399266 580081 589160 34217 123766 954856 53760 981162 192363 888000 946691 822965 266138 826517 663217 109248 341230 927932 560091 636406 911788 263189 607172 934561 820221 19671 58845 471771 253612 893462 945614 920909 564165 560946 101029 953902 201345 35126 295798 913611 247623 67196 766955 257371 50745 16636 467048 28228 161044 334078 704329 968649 787980 511383 392333 81933 633449 20848 778301 857106 607842 126155 710200 461101 622679 893640 349941 887445 135329 535394 752020 417447 790113 101334 764912 573986 240039 78115 913111 531470 27491 766707 711101 330836 893118 30550 73581 261367 955558 23449 71755 266671 355631 635176 510305 928043 479…
Output: 1585940547

Constraints:

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

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