CT37214

Captain's ledgers Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Captain the reckoner watches over the otter slides of Sleekwater's stores of ledgers. 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 <= 2878; 0 <= a[i],k <= 1000.

Example 1:

Input: 1956 527 884 851 424 648 967 708 478 947 901 134 70 628 268 490 529 325 784 90 234 731 347 70 325 851 739 221 873 122 189 412 803 500 403 678 272 766 906 59 353 802 924 764 900 67 130 85 361 219 172 831 230 113 269 982 951 961 177 916 691 591 484 354 697 62 246 861 827 305 311 576 152 164 787 707 872 650 347 869 491 319 593 395 826 845 756 170 929 459 333 189 512 257 121 294 859 535 404 473 994 41 699 233 3 52 563 264 872 431 877 23 635 42 515 631 359 578 325 208 520 943 147 557 294 778 718 116 74 200 71 673 49 723 262 553 839 276 505 243 805 550 244 490 149 820 518 553 658 307 119 284 157 681 462 557 144 147 5 638 906 426 936 11 529 225 117 171 154 207 946 33 747 50 20 272 662 410 295 653 975 871 985 527 115 815 734 259 91 80 495 549 799 43 192 899 527 503 181 949 151 722 916 748 20 400 5…
Output: 527

Example 2:

Input: 1907 1777 974 114 133 858 381 39 538 645 16 210 759 188 331 694 828 874 99 104 623 847 396 948 894 484 657 705 29 909 989 895 262 35 869 862 326 698 69 661 75 933 203 835 565 103 494 445 719 16 345 881 111 748 391 978 149 547 99 329 918 947 645 428 681 197 518 617 601 526 398 658 383 10 311 95 790 667 467 128 808 933 113 990 385 206 192 74 578 486 523 459 420 544 151 818 926 767 417 633 754 261 379 142 211 956 691 394 281 550 585 681 88 761 564 106 509 35 399 391 539 829 285 870 256 521 487 767 618 657 505 134 183 129 72 286 877 697 707 266 794 568 850 151 571 677 888 960 393 319 388 604 325 359 402 489 680 925 830 238 943 150 284 244 759 416 52 687 381 743 661 388 719 299 870 637 834 601 209 948 985 436 63 26 76 422 539 863 504 448 686 922 123 724 659 330 834 479 747 992 525 380 227 49 58…
Output: 1777

Example 3:

Input: 524 1154 981 431 68 988 495 20 142 27 851 703 413 28 960 715 104 502 150 989 898 358 835 12 67 197 520 830 30 374 847 436 287 67 99 135 853 163 458 474 629 541 157 744 229 195 494 112 327 917 254 719 774 465 203 111 636 617 500 75 210 906 629 108 751 438 615 607 68 848 664 150 164 459 477 572 532 418 959 174 639 34 4 417 573 117 946 411 844 244 735 58 32 340 774 907 297 87 853 932 559 365 63 127 999 412 92 1000 57 101 123 979 340 751 590 100 46 84 440 33 706 118 50 551 402 824 279 204 43 571 287 274 233 121 997 214 83 881 683 512 772 92 34 575 448 5 773 161 801 43 793 705 323 52 788 196 237 504 831 849 727 117 894 459 842 369 217 378 793 308 205 639 603 786 387 624 882 957 852 752 543 677 620 513 319 542 770 436 465 782 569 191 297 443 644 48 288 419 764 550 908 937 790 199 748 380 55 45 8…
Output: 1154

Constraints:

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

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