CT51007

Ember stretches Rain Ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the tannery row of Leatherwick; Marek weighs the day's stretches manifests and starts the calculations. 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 <= 2897; 0 <= a[i] <= 1000000.

Example 1:

Input: 566 863284 920308 500493 198331 770679 836436 149294 821908 774818 946464 12528 74598 852213 331161 454690 178195 166454 296359 879376 54268 26617 405160 97279 595754 275380 378732 972740 819027 622797 665176 867253 932396 328138 942651 294649 575637 406212 319801 851905 360381 376408 137574 443875 345755 576568 546757 448990 590506 938659 68229 660128 307347 691547 894128 567024 101222 952789 593700 413005 540296 360546 790715 55975 298424 784677 842347 488316 440987 310339 278104 335623 286948 686813 370942 51272 631116 838960 125017 178617 751312 104199 544415 556583 477842 813798 78662 476243 719197 338112 915434 354934 955968 102747 987331 684289 857206 870703 956738 535696 396214 153215 419057 946538 357451 515285 532914 940781 830879 13224 357878 197361 286866 928482 292405 78386 30…
Output: 276361749

Example 2:

Input: 385 525617 286503 188460 54808 889032 258913 886443 90202 52582 582567 193453 721111 603138 34576 987518 357026 588093 455258 651395 507542 403596 27412 670754 240797 760289 77497 35065 633265 900406 481016 201645 768559 598441 762105 833770 256636 513632 907010 690307 406881 999937 577608 685340 416914 409080 3059 591592 428516 976257 442400 572179 959274 556251 853773 464082 441395 124536 374424 958356 793711 599558 134100 111975 554063 409158 594094 851861 539392 977073 794077 788040 325836 335013 174531 98093 657514 126668 95384 981747 174921 605981 800300 134696 44053 206680 134671 814254 497001 595366 789022 888467 420432 616827 271813 440702 948952 309536 726963 445956 62869 244190 511466 857114 295190 841941 795213 322507 781903 772137 990999 176534 697965 704331 953367 647187 9847…
Output: 181832309

Example 3:

Input: 328 518903 975894 805935 939240 413093 380736 95225 581101 56953 439343 470249 916223 350016 134827 152337 678378 744443 583275 829361 579931 420983 21910 560460 924132 428288 770567 963027 564364 122931 356889 695057 933410 2971 190440 706304 826195 515263 452143 943255 900695 480056 726931 512657 783190 13139 236259 902229 46320 690824 351499 229916 479727 600132 945119 145492 805841 155345 102949 766184 637753 371265 765565 476439 4508 46960 914656 34711 329077 336990 252813 384848 573578 182621 676060 881900 214492 751202 339699 873585 118790 842092 487963 390463 774683 987852 195630 692197 666120 712659 293236 675012 365264 754367 541763 61952 875362 408829 867737 766297 879596 785274 661743 329442 97939 217922 588037 263058 993607 530906 379935 91003 651614 359141 159930 749597 87978…
Output: 155054191

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ember stretches Rain Ledgers - MEDIUM Coding Problem | CodeTikki