CT43527

The Opal Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nina the factor watches over the ink district of Scriptoria's stores of vials. A careful computation stands between order and chaos. 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 <= 3967; 0 <= a[i],k <= 1000.

Example 1:

Input: 2347 760 93 974 919 270 402 681 588 411 338 386 694 827 162 598 13 919 72 957 36 942 631 717 349 339 450 459 27 324 376 87 350 820 428 910 704 695 879 379 666 199 928 434 181 415 493 713 77 499 966 938 151 899 64 520 423 476 350 847 120 837 574 531 150 486 846 382 463 634 838 268 376 885 727 792 730 911 780 222 751 35 238 62 37 470 710 465 421 625 492 339 844 647 900 820 577 415 957 699 153 197 350 286 438 878 468 485 838 606 444 265 913 63 657 803 603 945 261 748 636 644 361 602 929 344 647 262 259 990 426 375 616 323 352 481 213 14 645 503 198 603 470 144 40 27 917 380 766 227 878 605 767 454 765 356 931 123 629 124 327 568 617 772 921 23 111 683 635 35 155 436 689 515 688 940 135 368 33 426 3 931 696 234 784 270 787 336 383 72 288 656 935 623 911 673 810 602 820 801 404 231 368 425 589 …
Output: 760

Example 2:

Input: 3766 725 793 619 164 389 872 503 516 199 117 534 85 932 877 819 491 381 669 248 79 726 822 135 852 856 192 151 178 285 984 136 67 419 769 386 369 262 489 91 343 557 340 220 762 121 695 171 300 113 293 407 857 249 526 522 642 227 561 538 45 209 941 249 843 827 325 98 606 303 640 437 572 390 357 57 309 674 39 572 484 836 636 695 493 718 31 393 699 148 700 256 718 477 588 68 797 805 615 491 175 909 530 946 568 303 539 122 152 394 450 854 104 323 778 64 367 499 36 610 140 984 948 90 174 906 120 347 561 868 114 388 751 997 957 609 232 100 951 652 420 537 629 205 305 281 209 846 698 273 354 968 762 659 512 95 696 812 965 210 675 288 770 697 886 822 653 44 456 877 126 619 702 926 244 986 724 579 648 196 361 359 63 67 332 66 477 851 297 142 391 230 632 247 40 28 477 471 772 481 45 428 523 320 827 …
Output: 725

Example 3:

Input: 1093 1443 775 344 130 265 292 383 246 640 98 746 545 81 514 813 126 710 199 943 820 495 678 792 362 471 32 725 441 783 465 599 258 905 515 931 290 773 316 299 363 87 786 141 348 704 564 37 240 954 428 362 951 459 836 711 460 789 121 948 393 814 320 959 769 31 37 889 135 610 187 721 477 218 900 69 970 77 203 711 592 676 210 623 706 619 113 103 676 795 4 946 546 536 203 612 948 855 422 665 233 240 427 66 638 937 103 400 265 535 815 459 511 761 615 299 705 429 293 515 575 358 834 970 837 70 539 978 659 226 720 758 789 631 966 98 344 372 671 346 594 390 358 393 863 953 361 931 407 811 189 97 39 211 49 433 614 385 724 558 726 965 961 435 177 467 835 491 853 822 663 497 949 389 357 205 902 41 748 874 964 712 943 132 920 787 21 608 701 524 159 707 49 60 572 431 550 93 681 483 671 540 979 882 381 …
Output: 1443

Constraints:

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

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