CT62115

The segments Rain Ledgers Puzzle

MediumL6 · Pointer PhantomAcceptance: 0.0%XP: 100

Every season at the cotton rows of Whitewick, someone must prepare the winter inventory. This year the task falls to Nandini, armed only with the segments register. 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 <= 2183; 0 <= a[i] <= 1000000.

Example 1:

Input: 1254 382189 653196 809110 411010 846658 913558 178266 92367 292997 637315 838733 152951 576220 3591 382773 152986 61717 518489 572618 902628 99112 320597 546243 188427 998604 766736 234002 768005 747689 983938 339630 98318 272254 993570 97807 604974 577881 797077 434822 959092 112355 675354 466006 606480 334337 739318 478862 111235 197998 287565 48370 373528 815684 131319 231858 138720 430143 444862 168803 189134 620849 433031 694523 584915 396927 58962 79915 493405 345777 99085 392809 75638 485151 88824 89828 620155 438814 936252 495681 345314 347330 771557 205099 205428 337741 253473 998732 17595 48121 351330 526398 595903 732328 537136 806174 797938 485277 361673 471235 459552 659150 327512 656664 975268 965381 772179 515207 218562 952936 738806 931146 348962 847021 847458 549206 977234…
Output: 615184719

Example 2:

Input: 369 264980 118084 192963 84668 94564 276797 845199 105479 132228 439454 909176 289034 943117 266472 609576 491409 621065 661564 120410 925790 382903 377475 568891 11075 601758 457324 321852 548656 630773 183176 649932 197888 327305 856736 225544 580397 496561 849181 399551 651892 729462 100808 932483 399717 887419 936032 906224 983671 95789 995302 802055 290348 318908 501396 148590 51157 523966 62036 506737 583373 805551 80813 853713 49329 285522 703763 164745 525621 472757 625153 707479 755944 512880 979222 888926 657422 991513 604837 360938 240592 206383 37934 976156 330462 656478 547076 119754 541555 310516 438750 540026 172565 814515 758542 86349 12622 714220 195434 857434 278358 987595 301346 438320 234653 351108 385008 311695 329691 383016 37218 253157 576662 585663 809960 344967 493…
Output: 172003533

Example 3:

Input: 888 155346 61872 481196 142038 723163 793609 394797 953679 74388 121377 117103 409503 10615 1137 885076 168148 132247 234861 678519 585330 210517 74771 822161 715580 246468 6624 412478 565996 871860 389048 111252 130130 666378 800749 375088 134472 830860 304294 367467 383880 176582 961642 639330 859720 838934 132621 992768 331136 333546 237895 264939 928181 146143 623411 182316 236121 186376 818217 908413 625448 921685 412356 763950 225569 54495 506195 745684 800238 606917 797214 414202 104247 389816 474780 38228 498043 418833 118387 668938 903483 263290 262159 79938 880825 707501 107542 383671 520766 720890 114555 985517 793086 108901 931832 767233 962024 46452 889948 361240 698305 446313 180052 573468 535815 105293 917789 747661 329003 928183 13753 849137 153670 640054 87026 8457 380210 …
Output: 431327617

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The segments Rain Ledgers Puzzle - MEDIUM Coding Problem | CodeTikki