CT36859

The Nearest Pair Sum Beneath Vermilion

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nila inherited the ropewalk at the cinnabar mines of Vermilion along with its curious bookkeeping system for vials. Time to make sense of it. Task: Among all pairs of distinct elements, print the pair sum that is closest to k. If several tie, print the smaller sum. Input format: First line: n and k. Second line: n integers. Output format: Print the closest achievable pair sum. Constraints: 2 <= n <= 1922; 0 <= a[i],k <= 1000.

Example 1:

Input: 532 1303 373 774 691 936 508 948 446 329 814 293 337 193 127 42 194 758 272 753 60 397 218 141 384 420 645 728 304 163 443 35 117 482 871 58 351 32 157 469 162 3 939 218 698 276 382 125 390 343 856 882 496 80 500 421 271 327 678 700 790 311 330 751 303 81 981 559 609 288 685 469 132 980 770 472 863 240 518 900 781 708 478 332 703 93 917 712 651 177 154 920 129 85 299 842 210 920 495 812 952 446 289 44 692 639 991 446 589 474 512 813 859 590 942 301 712 494 846 546 817 840 442 574 231 952 73 361 263 538 860 818 423 791 573 321 273 880 423 971 170 975 584 336 318 786 161 379 409 948 466 392 444 771 341 626 723 797 328 265 275 942 421 15 431 783 660 111 95 876 6 223 153 608 815 265 517 239 815 907 464 285 723 749 254 692 732 723 499 240 385 524 927 733 138 840 192 385 251 385 950 915 472 575 …
Output: 1303

Example 2:

Input: 1536 1913 587 446 509 380 827 205 200 666 485 32 440 141 114 562 7 557 7 589 230 701 59 685 837 355 367 924 337 930 407 747 534 676 749 70 79 430 33 8 614 946 986 845 471 709 158 729 791 610 311 898 889 167 660 607 651 582 744 123 729 994 879 270 93 306 759 796 481 559 188 213 93 222 913 297 903 891 917 466 826 269 939 624 552 868 173 350 726 530 645 664 283 991 404 9 456 813 840 558 938 774 73 181 513 84 57 344 913 300 182 0 425 482 500 811 565 319 855 555 673 906 12 284 889 217 822 402 353 31 254 304 939 245 659 86 42 237 209 406 566 959 531 952 880 124 117 196 272 522 331 728 722 734 252 838 689 687 907 32 706 412 218 701 804 760 663 342 833 376 962 223 881 815 161 780 191 49 94 13 181 46 651 680 848 17 415 94 44 332 595 469 947 22 270 766 352 374 31 378 325 800 335 910 440 195 253 988 …
Output: 1913

Example 3:

Input: 843 411 856 2 54 211 445 707 595 670 118 469 818 97 473 655 889 171 919 477 925 548 118 652 966 371 256 910 511 621 685 489 552 863 312 421 725 849 18 767 177 714 614 885 934 803 990 623 69 822 711 753 954 466 707 581 567 540 578 751 540 991 532 250 883 706 651 101 767 515 566 355 153 903 896 302 301 641 75 367 662 460 519 238 959 476 827 374 946 501 318 392 344 507 144 329 678 288 210 181 356 300 970 605 2 85 906 480 988 82 122 504 164 788 132 650 176 757 861 481 777 521 302 342 613 370 973 136 844 481 266 837 816 322 397 56 540 929 164 225 514 618 477 858 562 434 993 337 699 364 975 791 784 715 746 682 238 926 769 7 443 92 106 837 137 779 232 69 95 573 582 126 575 791 455 11 179 523 881 586 897 36 114 712 922 736 527 495 546 471 946 614 257 66 938 153 777 144 402 67 305 280 757 809 232 9…
Output: 411

Constraints:

2 <= n <= 1922; 0 <= a[i],k <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
The Nearest Pair Sum Beneath Vermilion - MEDIUM Coding Problem | CodeTikki