CT52102

Freya's Secret windows

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the desert outpost of Sandspire close for winter, Freya must finish the windows ledger - one figure at a time. 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 <= 2167; 0 <= a[i] <= 1000.

Example 1:

Input: 619 650 531 346 750 99 48 417 228 648 219 121 80 438 870 337 417 486 758 247 136 62 286 461 299 726 228 343 944 619 745 756 111 863 134 582 672 77 104 980 922 79 763 539 723 897 854 537 977 523 860 998 248 506 84 711 729 733 956 323 254 916 750 904 426 915 476 129 282 82 508 176 921 624 664 519 954 105 850 556 198 40 73 904 425 987 708 347 381 235 315 869 907 578 60 971 411 142 207 573 501 374 135 79 533 350 851 571 837 190 11 369 53 233 965 773 485 357 307 511 841 2 587 269 353 835 372 547 396 715 840 627 846 921 943 615 701 531 584 67 421 22 815 904 601 336 307 176 78 635 872 923 893 175 702 7 887 555 552 345 237 398 664 390 881 450 206 211 786 770 854 640 847 457 430 503 818 905 294 246 817 278 552 913 675 362 28 38 123 631 715 148 151 709 403 559 558 770 144 608 384 151 861 335 987 308…
Output: 290947

Example 2:

Input: 290 719 380 357 658 860 762 49 852 657 920 722 566 674 17 977 898 597 600 809 82 327 579 994 413 300 310 433 850 188 895 905 721 163 163 377 562 525 663 996 642 717 180 421 464 271 234 458 23 897 887 84 468 449 805 307 518 2 94 598 337 706 412 59 517 250 351 935 523 621 381 771 519 409 897 922 135 896 965 324 192 867 11 864 33 282 384 272 912 239 925 378 710 24 715 957 414 940 498 383 321 153 442 131 887 603 779 62 17 637 732 755 247 726 488 185 79 933 495 512 730 41 459 760 159 672 119 618 591 723 905 490 455 207 191 180 252 53 945 646 180 163 975 91 566 892 40 262 667 121 751 399 207 704 29 902 815 139 852 9 846 335 142 558 395 389 775 976 638 580 569 885 36 363 561 399 270 1 892 78 75 672 501 903 199 878 931 421 722 806 455 222 609 677 111 552 824 422 186 471 516 120 491 252 996 333 161…
Output: 136530

Example 3:

Input: 1084 171 123 476 328 308 272 841 50 114 777 907 3 593 749 779 848 112 410 627 740 910 830 259 58 989 122 852 853 702 118 817 810 901 570 841 313 774 355 379 658 797 968 226 978 664 644 72 521 122 433 741 191 989 672 426 335 229 961 623 587 933 296 604 425 191 156 305 300 547 842 796 668 738 669 828 304 848 323 439 467 97 579 496 633 880 227 469 946 30 606 43 62 75 83 368 9 128 860 974 669 234 883 653 97 344 947 26 754 534 784 3 870 757 999 236 863 43 440 337 140 348 469 709 303 958 268 633 866 377 222 629 710 499 649 604 847 624 621 473 588 510 928 391 735 851 298 407 327 409 152 683 965 438 894 764 894 368 173 318 777 356 286 643 702 697 108 575 29 293 996 492 859 477 677 914 536 587 199 266 785 413 882 674 59 784 456 932 340 719 754 668 311 24 776 286 358 398 727 778 908 616 484 547 867 …
Output: 530632

Constraints:

1 <= n <= 2167; 0 <= a[i] <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Freya's Secret windows - MEDIUM Coding Problem | CodeTikki