CT29526

Bhavi's ledgers Reckoning

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Bhavi runs the gallery at the honey farms of Buzzwell. Today the books show a list of ledgers, and the numbers must be worked out before sundown. 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 <= 13983; 0 <= a[i],k <= 1000.

Example 1:

Input: 12854 1961 279 243 490 538 383 810 265 172 241 985 559 912 726 170 335 654 72 55 425 681 485 684 157 559 81 541 507 553 975 708 148 531 909 124 976 470 555 68 597 711 317 45 37 650 53 397 905 889 961 505 366 384 797 723 462 57 541 614 619 6 865 353 161 288 855 331 34 760 140 661 538 438 588 84 771 635 890 940 931 164 543 864 612 55 604 848 930 754 893 446 110 829 150 662 94 56 491 509 104 334 546 772 27 775 548 542 642 436 358 679 479 888 497 427 918 427 82 321 379 84 939 175 582 191 979 423 232 421 62 165 604 245 823 5 226 489 379 423 906 522 847 573 998 693 658 744 765 954 852 363 982 242 408 252 506 46 512 156 797 871 864 549 630 693 161 573 385 615 781 367 981 563 613 836 812 111 998 698 200 240 907 669 569 423 137 426 229 151 796 30 163 391 915 751 828 83 93 392 191 168 12 642 679 827…
Output: 1961

Example 2:

Input: 3919 1588 12 895 809 54 122 582 204 523 966 567 701 142 816 508 351 493 73 712 260 469 265 91 438 878 921 413 302 45 164 567 79 287 776 432 628 21 516 542 49 54 146 384 70 520 355 794 418 31 29 519 967 79 127 323 824 967 13 543 271 977 844 417 867 246 580 328 501 217 518 685 368 900 639 368 608 430 254 830 414 317 976 839 427 65 738 744 978 470 987 607 651 865 238 514 395 225 521 284 248 242 263 647 879 658 527 844 353 621 607 170 403 860 90 865 2 348 291 836 468 699 806 521 469 904 669 125 3 982 421 716 701 450 919 815 126 173 94 7 760 148 779 200 374 372 577 669 505 539 109 23 282 839 716 700 543 817 876 722 261 254 462 202 789 499 580 522 187 524 581 442 118 647 394 194 815 165 782 353 617 221 136 274 574 675 98 726 90 923 546 654 557 274 524 107 640 762 545 477 708 809 226 414 1000 939…
Output: 1588

Example 3:

Input: 11848 1864 632 437 3 640 118 865 565 967 710 958 316 478 868 556 144 448 6 622 634 765 490 720 590 103 792 708 24 542 329 37 120 765 666 575 171 638 582 502 672 471 518 414 605 888 763 314 903 40 845 103 712 974 417 392 934 669 102 686 348 245 714 81 743 727 684 87 407 360 929 32 336 85 133 618 791 37 335 565 385 572 151 828 4 747 519 635 645 845 201 974 232 111 774 741 867 747 415 76 702 728 964 153 92 750 393 266 572 591 600 158 37 525 311 20 154 10 95 971 841 13 519 909 931 66 933 485 140 563 969 488 349 661 349 92 314 585 358 392 525 713 591 33 946 614 90 56 187 694 384 157 755 36 476 447 532 921 765 510 645 949 704 920 427 730 801 216 743 982 51 957 319 484 235 83 902 820 592 803 223 282 879 443 636 561 953 341 676 397 855 360 978 963 849 943 125 148 206 260 820 58 504 822 186 980 394…
Output: 1864

Constraints:

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

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