CT55157

The weights at Coralcove

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The paymaster Quill has been asked to secure the caravan contract. 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 <= 3967; 0 <= a[i],k <= 1000000.

Example 1:

Input: 1538 552211 385894 90670 572782 216974 34275 913901 422644 911531 869771 128331 495634 383524 689824 978375 478163 437652 434906 359286 761349 342124 95871 272499 434474 381135 672475 852988 826046 142605 251926 6991 959964 177869 485218 832994 328913 287124 312034 349281 658119 358439 862935 505443 196251 843536 424284 732238 103074 947184 689192 210589 227464 451802 242337 250264 842332 329151 853505 264799 54770 488279 133162 185539 241702 704050 215668 661933 411960 40693 959449 209691 313041 184964 161677 930487 596645 701563 436721 230137 498301 456620 605115 800916 626766 232797 204479 716110 362300 669818 291783 637345 507757 452481 934208 456400 909099 869723 12735 665212 118607 851155 608591 565745 852416 129480 966398 109477 126424 43271 5674 928051 710079 260956 543217 126417 6…
Output: 552211

Example 2:

Input: 2089 861083 354693 224534 12988 424284 953523 439010 79989 414711 403409 592813 648170 575167 950068 552300 898496 830701 655905 890235 265723 637824 123513 863356 665603 46312 193583 504483 39834 380669 301147 226127 958427 65070 791602 908311 652593 203958 177289 272294 233572 515829 357028 484853 947145 802293 645525 750174 845585 833140 153380 434835 918394 500070 192593 940935 825739 511740 99807 177219 392045 613059 454387 350295 217868 401076 186404 340569 661524 295838 32572 159214 755963 690579 771459 8367 751533 245991 276692 449100 709887 908111 222866 79214 6429 324018 618280 953453 893386 153770 821784 131568 550406 595579 397721 320712 635424 935005 629709 598558 790671 927690 122975 874145 870136 781115 46919 610916 767713 377769 885061 82819 562762 757680 318298 473354 8901…
Output: 861083

Example 3:

Input: 3559 430968 911206 661261 91466 811364 27886 767067 618221 832688 560266 934036 671453 17467 485058 702717 822677 630851 619000 67341 260450 869903 584976 245680 899841 965392 983649 274169 204141 897111 160732 595534 382199 126544 142670 966040 426290 666772 476614 395028 983525 738992 937539 122926 280387 40474 192403 788093 82717 687460 829554 570502 60160 216308 617784 307875 199024 829727 183294 963453 262916 591295 316603 837381 14452 930071 718382 828248 964417 32513 878742 96175 14785 611165 155348 919559 265060 782476 515165 171630 85197 183588 905057 243343 170381 698778 820074 817362 184410 333045 520898 80743 448071 539747 414807 161473 434839 491715 150455 240467 122936 79067 990371 769300 669268 111658 854842 487645 89083 208344 580966 314469 438724 198072 511969 653394 98902…
Output: 430968

Constraints:

2 <= n <= 3967; 0 <= a[i],k <= 1000000.

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