CT49140

Wasim and the Caramel registers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the trading post of Goldmeadow opens only for a perfect tally of registers. Wasim means to find out. 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 <= 3695; 0 <= a[i],k <= 1000.

Example 1:

Input: 3149 1535 640 593 524 332 923 933 67 177 958 82 524 968 119 35 635 748 529 892 337 229 721 134 976 829 413 207 152 986 560 885 577 685 803 348 322 744 230 361 96 193 260 657 352 487 63 703 840 149 927 196 401 630 984 827 914 787 43 205 704 797 855 417 269 347 60 731 788 172 217 219 887 957 992 913 837 951 448 831 586 301 370 231 881 416 204 460 257 218 49 816 822 806 927 433 744 307 48 729 132 441 764 378 343 531 979 244 130 442 865 953 931 448 322 570 664 184 578 59 884 167 269 36 390 652 816 738 177 263 644 99 164 242 43 544 559 18 164 611 917 716 904 137 801 40 281 687 939 140 35 751 403 962 61 736 428 618 829 629 46 556 606 445 639 110 268 647 302 212 274 15 961 204 319 534 82 852 25 462 921 5 171 53 896 275 163 867 772 569 837 922 197 835 669 347 722 151 495 588 747 79 559 828 885 318…
Output: 1535

Example 2:

Input: 766 1395 795 756 16 329 975 609 340 882 715 509 121 413 420 913 363 110 677 204 302 359 860 458 87 99 494 500 96 321 915 570 5 900 736 896 751 412 520 210 689 291 123 772 840 569 234 897 481 104 143 857 985 133 200 16 643 313 896 460 269 206 853 241 286 352 684 519 369 397 299 112 242 903 717 991 18 614 31 592 116 476 634 291 372 122 325 869 641 446 819 830 194 4 388 516 578 763 642 168 267 735 791 584 284 212 415 434 628 876 653 602 912 842 882 404 496 387 690 722 282 785 740 904 569 519 712 656 829 643 657 601 352 245 652 804 283 576 155 289 309 267 418 496 206 768 529 271 301 981 852 343 525 417 563 461 406 98 433 776 692 334 373 826 732 239 861 600 653 227 955 905 423 220 620 101 834 9 64 933 18 706 623 295 588 59 487 573 319 942 388 134 410 493 412 937 408 877 735 700 475 159 295 688 …
Output: 1395

Example 3:

Input: 894 809 827 602 811 449 904 166 567 587 27 234 995 246 293 307 506 616 306 908 651 890 493 46 68 887 328 282 737 137 873 919 187 561 966 72 727 203 438 324 140 953 777 781 851 588 126 775 502 904 340 347 515 866 439 542 438 53 91 848 745 620 31 193 910 667 355 469 520 695 91 684 742 785 116 933 363 194 224 251 822 432 572 464 677 546 382 740 818 128 244 831 153 149 400 645 280 658 810 472 164 799 466 733 517 67 367 534 990 257 821 242 796 513 242 747 305 297 925 436 12 365 117 906 147 62 54 42 803 919 707 507 392 130 593 911 318 408 147 470 669 498 145 593 974 893 478 448 81 52 43 1 284 594 484 248 266 221 970 737 272 970 893 922 123 665 638 935 384 586 205 464 198 930 641 674 304 874 1000 999 186 327 678 967 94 516 218 971 567 130 137 9 81 601 446 458 672 748 199 55 734 606 287 453 441 16…
Output: 809

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Wasim and the Caramel registers - MEDIUM Coding Problem | CodeTikki