CT48034

Whispering ledgers Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the caldera rim of Firewatch as Jarl unrolls the day's manifest of ledgers. The tally will decide the next shipment. 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 <= 3174; 0 <= a[i],k <= 1000.

Example 1:

Input: 457 1986 79 835 938 657 338 114 452 305 147 619 188 332 792 869 364 699 877 873 546 519 845 689 7 40 744 26 344 139 652 979 119 26 156 183 944 617 779 389 878 950 272 32 777 985 857 441 362 132 864 898 734 430 748 728 749 755 823 733 388 682 484 115 486 385 263 232 837 724 57 508 449 542 951 35 498 93 424 483 558 457 160 816 915 235 484 530 490 69 493 970 59 817 741 123 779 187 202 435 127 407 720 515 419 574 750 552 337 735 351 197 625 560 302 368 683 385 170 288 143 327 1000 589 613 708 587 607 519 868 137 413 118 337 30 413 125 513 578 205 760 77 784 20 555 644 38 964 825 764 351 851 179 812 762 900 948 784 914 767 742 77 815 855 65 130 639 103 795 156 768 407 211 243 149 733 767 402 861 297 730 956 548 833 198 740 432 590 970 861 596 919 15 390 319 21 6 877 23 948 684 565 213 473 125 2…
Output: 1986

Example 2:

Input: 2003 164 420 710 415 127 248 970 232 243 26 524 904 224 640 213 413 519 751 878 942 69 797 781 993 592 558 507 787 438 662 912 855 520 169 99 100 856 365 288 827 651 586 409 633 149 179 363 607 555 537 308 117 478 281 690 52 157 380 231 89 913 51 177 249 809 319 549 387 213 173 415 99 668 169 48 43 249 390 228 130 789 855 485 85 844 798 458 392 606 959 826 907 283 326 790 511 478 259 925 75 258 865 283 874 788 955 952 978 885 958 478 222 846 493 228 705 736 944 485 4 352 820 776 285 385 176 775 109 121 352 867 878 97 363 653 347 775 507 896 856 664 772 895 389 934 624 45 661 676 331 396 698 922 961 755 453 567 160 208 428 874 375 317 83 531 693 865 755 609 588 705 883 663 841 203 992 677 525 332 367 687 511 969 47 349 506 951 620 218 44 852 972 823 278 655 583 925 868 632 621 223 566 872 7…
Output: 164

Example 3:

Input: 1299 1106 827 154 942 286 418 236 334 591 832 192 589 708 739 747 950 489 365 445 858 781 815 393 77 620 912 109 962 259 897 974 136 300 600 79 226 246 92 654 502 688 91 469 539 272 140 700 214 844 692 585 903 222 920 872 600 191 289 270 469 785 93 362 674 118 949 153 258 460 564 955 343 251 190 756 599 19 746 542 334 651 717 796 238 176 173 78 548 826 849 190 129 463 592 548 775 825 938 207 84 611 669 519 89 112 593 169 40 821 826 417 318 632 332 175 957 839 839 470 548 285 534 782 565 71 572 69 157 637 976 549 202 72 216 901 993 438 118 930 928 357 979 130 82 715 115 811 852 496 54 737 890 198 482 607 493 690 724 150 554 386 744 193 678 683 786 61 345 942 903 938 52 604 353 790 857 112 949 1 935 567 845 949 992 269 865 354 360 322 800 910 294 15 629 764 485 237 571 715 43 962 621 333 106…
Output: 1106

Constraints:

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

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