CT45056

Starlit ledgers Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the windmill fields of Gusthaven close for winter, Hema must finish the ledgers ledger - one figure at a time. 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 <= 3859; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 890 -944282201 -675392656 -249763427 -40946802 -32718337 -468435980 -760985404 -485422311 -391183835 -127881518 -360082549 -87591569 -189942868 -491445157 -991823395 -287725563 -977966156 -861373322 -710948212 -221682241 -862527517 -958598372 -666834757 -589331514 -785666049 -982201817 -144251292 -766625318 -406536812 -890419794 -937890647 -734889245 -121484434 -772428273 -692601241 -846806189 -380628832 -461320122 -799785602 -446830485 -158298853 -717786428 -950726223 -713756244 -377141054 -634349675 -446731439 -211387072 -725934328 -110446677 -364792762 -659186687 -621373878 -305999782 -634049415 -850779501 -9431748 -317066748 -328475828 -74095114 -87286694 -266162085 -532379459 -47704259 -582693567 -295697048 -161742667 -276871712 -68067496 -999864687 -694649314 -251332740 -444749313 -6…
Output: -944282196

Example 2:

Input: 2202 -159212001 -77368004 -193281226 -423099776 -347576589 -959071149 -723536569 -955477487 -551384576 -358327151 -241233402 -95489057 -829450730 -772749497 -930578711 -277799629 -791450008 -826379216 -738429857 -26541912 -113284541 -550451291 -257847706 -909707776 -680891110 -152301890 -596863185 -537515692 -723276083 -153179170 -200559653 -135560566 -445934078 -894147206 -432727095 -805790969 -164492295 -204319116 -979348565 -317083318 -843786234 -199624711 -700031685 -885407465 -759478460 -806261231 -574791042 -757491327 -374339592 -547390027 -327934624 -573430440 -865283311 -359398009 -797153401 -795912122 -829967212 -258592921 -595463412 -70157397 -727467679 -32021905 -685134562 -31179603 -102947816 -690787573 -569473255 -334572051 -67547218 -481799313 -260437661 -352876570 -804900632…
Output: -159212728

Example 3:

Input: 174 -448364994 -946748541 -825704972 -494468666 -745089870 -803008385 -954168702 -148836787 -611369708 -498550085 -867679298 -178134222 -39261474 -174307171 -904704441 -138465447 -666261056 -261269248 -144667417 -23139786 -4586717 -513696329 -766760641 -886018888 -227460863 -783689708 -749102690 -941788973 -821342072 -597586765 -424234299 -208114207 -869911441 -934626125 -539580072 -346659369 -549195089 -521528708 -840907767 -362418637 -592784601 -24617109 -240381699 -576026038 -214967982 -784298480 -63499846 -589488556 -354314082 -682055504 -266820486 -289341324 -388248752 -965098927 -902861633 -269236163 -71662515 -781790426 -744541132 -899765873 -834548383 -426234596 -577080935 -283390898 -612677388 -305047304 -246764006 -471395982 -805225414 -742115113 -497880924 -5414430 -514916751 -9…
Output: -448308596

Constraints:

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

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