CT42675

Lara's Nearest Pair Sum Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the shale slopes of Greystone; Lara weighs the day's weights manifests and starts the calculations. 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 <= 3819; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 3517 82630751 168751952 781610329 -352561063 -568734731 402491030 -459781764 -989432114 -148318241 -944061226 642495224 -96828356 -654643292 -667216687 -833095655 -848376530 975447431 999847662 -665764771 902881092 738793069 -855119927 718521325 707029905 -746843256 161453273 556744532 52426479 349820131 -323493683 -643835626 976320308 23966177 -657494546 -553770971 94541734 -477212698 479227138 -194914812 541477908 -773286892 355397763 -590180108 -117398504 -368906136 -126111455 -938636494 419625705 -822663202 -987968532 630383118 183433458 454004789 -742715198 -434401627 578751581 -698154699 543530909 644304965 148804070 692381550 287041299 115214123 -525331935 -211754278 -646819260 -530656046 678491643 533501243 -157564604 370702495 -80269298 -467922135 -372947243 -86308195 537246123 19…
Output: 82630905

Example 2:

Input: 1609 -880028501 892505618 289040773 -155981895 -764227470 813376247 736497830 530876244 -236844139 -526624884 -780406132 -911734259 206113853 -93610447 -455358892 373298324 -120635391 -538696014 17310501 13316072 -98157762 621709092 87126783 -146685678 -856704484 -727759272 -881330511 763466084 -295929446 -606673159 -449500259 817573684 -838119363 -574461775 757257168 -667715059 -416474531 399325735 -527225582 522597292 -361352129 -30221311 -554877804 -468501664 -179048341 -386392944 496269779 -174348518 -342306243 49797262 -660595509 733924798 -960384066 365959511 -547346857 213516690 -400516107 513645944 -701298905 -86354137 612625606 970038237 391959080 18026295 -146557121 -509370359 532127022 -773237208 -91230678 131203018 202819684 664032554 -702295777 -425592486 326846941 -266521669 …
Output: -880030679

Example 3:

Input: 3220 638503874 -359021351 -435703764 729723727 861916911 -695929782 269514395 -100353173 820188688 -943303209 -578060977 747542833 -180840989 79282330 229512491 -601291459 323154477 -640705557 874907312 -101983268 583796431 -606961979 87342815 296246120 789500969 481416431 863545014 -446028135 -51244241 -387417499 48215519 -555513309 -848631696 802860133 541213071 531568080 633493569 617735922 567639040 -496309092 -929633405 747206111 672687590 -751288023 -408547147 443677826 -445760324 273240986 -266691775 474341897 -197532395 -265358623 -825272547 524589707 994141013 315358215 357735318 -727098719 -172721202 696010701 -620485908 37179013 786996979 286581174 433199634 -831271396 -57507247 -152173378 -576381788 -591836872 -403997560 579073282 233682247 799032176 624033133 -109201119 -96577…
Output: 638503771

Constraints:

2 <= n <= 3819; -1000000000 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Lara's Nearest Pair Sum Ledger - MEDIUM Coding Problem | CodeTikki