CT50759

The Rustic Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the floating docks of Skyharbor, someone must file the annual report. This year the task falls to Dino, armed only with the crates register. 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 <= 3155; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 2268 -643297 -938294 -38341 -955767 -440932 -221615 -754637 -607721 -338559 -967496 -115902 -525248 -255400 -707603 -258707 -891136 -874826 -959574 -498392 -580946 -782071 -815596 -815907 -64749 -208018 -312377 -404594 -926916 -590989 -165667 -286520 -330956 -737873 -566321 -303303 -478295 -445534 -831924 -510107 -499000 -428798 -258707 -970451 -701534 -715150 -100271 -881608 -314453 -545356 -330570 -903477 -209377 -387204 -396075 -304509 -816261 -276696 -948370 -484787 -30611 -4689 -448206 -430566 -57281 -431235 -702067 -858332 -8332 -793146 -290205 -703562 -723509 -615021 -745293 -441255 -797562 -292006 -518834 -131660 -814596 -906115 -733443 -521719 -567250 -70205 -975664 -313777 -872587 -509297 -277420 -788062 -239524 -732818 -702674 -894203 -105964 -855811 -910718 -973014 -615955 -176…
Output: -643297

Example 2:

Input: 2001 -852349 -531426 -650240 -901509 -71413 -296311 -699991 -594888 -988369 -463562 -398182 -990974 -587813 -229521 -818101 -458891 -213154 -805272 -343870 -623035 -826665 -133326 -337356 -511294 -750183 -551465 -169625 -729952 -865877 -924779 -900439 -44615 -473085 -371632 -924360 -721607 -773292 -441485 -785678 -710518 -668529 -199229 -553994 -883958 -690941 -676715 -157773 -810634 -642101 -836439 -751583 -332623 -301788 -954797 -522823 -822397 -349673 -776655 -123948 -611954 -782851 -219797 -869706 -865111 -965018 -710484 -359617 -481206 -566401 -945847 -364647 -287170 -186129 -970227 -205135 -361088 -821717 -176355 -226958 -728816 -931778 -297077 -601415 -323789 -232681 -844658 -174219 -627874 -653150 -862575 -891483 -132799 -706001 -482833 -309226 -689684 -428065 -313304 -858251 -1347…
Output: -852349

Example 3:

Input: 2176 -447793 -802019 -106255 -859837 -785909 -331753 -165649 -502371 -243971 -534957 -194169 -858400 -588533 -859581 -721588 -242443 -129163 -418530 -832929 -8689 -953706 -436174 -217514 -880913 -138686 -928102 -23050 -649209 -524616 -109634 -533599 -328483 -359529 -800716 -799694 -221025 -461725 -970314 -270064 -539882 -750532 -654326 -583448 -586708 -714692 -674139 -951616 -729462 -478358 -48737 -711992 -907333 -991028 -784209 -352601 -759461 -450929 -25409 -746082 -251123 -443349 -428571 -495186 -345972 -872493 -795301 -933858 -750713 -428979 -882365 -70534 -950692 -395501 -126430 -713124 -670521 -282051 -868691 -724776 -18340 -506954 -502616 -661616 -589629 -142627 -928855 -284641 -218124 -852453 -537992 -558400 -392490 -202356 -304276 -147932 -709595 -631864 -50116 -290451 -714803 -56…
Output: -447793

Constraints:

2 <= n <= 3155; -1000000 <= a[i],k <= 1000.

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