CT44478

The Nearest Pair Sum of Gusthaven

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The chronicler Theo has been asked to outscore the rival chapter. On the desk lies a long table of weights readings. 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 <= 3095; 0 <= a[i],k <= 1000.

Example 1:

Input: 1863 1639 791 918 530 125 56 558 225 521 646 575 157 453 697 969 841 455 259 726 557 76 394 239 930 604 341 957 976 985 52 94 811 713 984 10 488 759 576 858 138 712 952 938 777 706 391 783 550 700 475 59 185 366 776 312 151 805 90 840 793 122 139 971 897 684 576 882 963 887 15 650 779 194 942 126 452 886 249 596 526 486 598 216 527 570 287 994 566 883 705 133 561 215 134 326 462 377 589 213 688 395 750 838 117 436 849 462 137 73 918 36 922 230 651 519 475 644 174 919 770 229 530 276 869 894 243 243 710 860 523 223 130 157 538 823 760 778 802 505 134 678 945 306 428 114 99 553 615 240 509 502 900 172 59 648 700 422 82 475 535 691 722 822 772 355 293 672 219 754 872 710 555 834 542 319 35 71 484 630 494 67 620 656 526 726 400 87 244 892 893 736 324 745 361 590 913 937 260 854 634 437 74 31 8…
Output: 1639

Example 2:

Input: 3082 802 373 842 73 435 540 897 721 274 329 406 352 704 206 123 827 6 573 542 24 774 678 851 933 183 704 245 330 797 680 773 76 261 466 382 378 983 604 725 222 349 676 30 17 246 907 657 123 274 611 525 250 833 866 229 275 65 676 974 619 94 28 294 923 407 208 318 147 47 831 222 480 925 216 776 970 217 702 581 635 394 705 784 610 547 768 710 900 501 938 735 298 287 985 348 392 987 738 646 24 200 474 393 413 914 667 780 961 477 278 241 514 559 848 227 657 731 142 667 894 333 520 629 430 59 930 596 764 332 99 366 82 765 395 553 748 947 980 366 617 724 858 603 920 62 113 422 684 759 142 217 719 361 737 531 773 461 115 993 35 800 125 538 520 439 54 963 504 455 722 77 868 624 324 487 229 412 808 109 686 487 909 262 545 422 358 218 87 542 404 509 500 913 543 85 438 180 643 971 102 431 731 533 993 …
Output: 802

Example 3:

Input: 2234 527 836 324 37 590 100 264 512 221 338 527 4 688 680 658 472 425 627 135 97 58 202 726 336 30 85 489 271 987 917 260 941 873 180 341 519 414 765 714 590 709 59 682 841 80 875 860 803 556 219 707 700 877 104 145 450 568 830 273 274 549 200 292 28 898 843 195 743 292 240 206 364 742 865 430 415 955 32 914 720 513 44 565 641 383 698 431 723 244 387 952 673 126 664 985 832 116 897 790 929 639 526 716 852 978 295 938 750 324 340 104 720 295 303 568 904 342 325 780 29 618 97 686 125 767 495 418 891 169 829 249 628 164 478 494 642 877 719 104 853 446 445 758 448 798 526 500 688 331 906 775 98 690 563 646 346 625 807 697 848 3 682 756 817 52 201 469 365 118 998 969 945 924 669 627 433 572 308 85 85 847 546 966 118 714 614 699 711 883 493 955 425 436 358 144 234 152 368 707 513 67 296 141 574 …
Output: 527

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.