CT44576

Northern ledgers Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the mountain city of Highreach, Dev studies rows of ledgers entries. One clean number will settle the guild's oldest argument. 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 <= 2156; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 1980 -62969023 -85752714 -493301400 -868832329 -310809132 -488884200 -104299912 -846274388 -291626556 -201217614 -359422567 -721196556 -530524409 -690729963 -633857984 -682755042 -302445610 -129075010 -663721385 -358154209 -589063626 -487429189 -966046319 -827744046 -338007962 -70366080 -33011085 -731123304 -995442180 -399025253 -605103510 -89236176 -308554027 -607259812 -922726478 -1780066 -161873583 -227563120 -773690276 -986553485 -690940136 -544053198 -434950073 -921865250 -992804705 -474867402 -529111081 -83852490 -232602194 -525159336 -368620448 -180897962 -136735099 -548281763 -184162001 -678295537 -147290411 -506733344 -73050099 -845658182 -850278898 -869961672 -172819009 -643681307 -68431680 -810284221 -146623813 -435808007 -270376794 -794835878 -121031800 -187055184 -900047234 -6…
Output: -62967370

Example 2:

Input: 545 -573721912 -534057577 -506776812 -25662964 -674084319 -306188685 -479022896 -90909317 -466772874 -924078708 -192347585 -369245400 -941871777 -107814666 -828115030 -180753849 -301925142 -108216401 -302233042 -130394537 -536707490 -17603859 -369004543 -127713225 -817525624 -551546066 -631592446 -341120181 -558048698 -154994710 -597022291 -725781135 -42106795 -942246138 -798394351 -151416299 -458831335 -940082072 -999339139 -425376257 -621482266 -118426476 -732843289 -968318392 -18792163 -798369123 -402494448 -55926182 -708661996 -603027003 -979009726 -259994984 -530911571 -159560230 -496357903 -503227040 -759607562 -571749135 -341444092 -104114849 -256698617 -79264149 -659187571 -738311783 -801609349 -252926198 -668807825 -489816677 -687255154 -513459344 -592625877 -855628866 -443661512 …
Output: -573721448

Example 3:

Input: 2064 -17570643 -645859920 -718041825 -407452695 -244645682 -956208958 -577922583 -595528369 -587152302 -618883885 -218130137 -466380823 -629054206 -330536119 -135751094 -423629746 -827522034 -902219570 -166985047 -360943413 -786362201 -569738543 -150084633 -117359829 -274280443 -677507987 -602955860 -658739428 -976399366 -986202653 -139149422 -970485483 -446119892 -420717155 -71292008 -902718545 -91611253 -337979201 -464092860 -264982929 -217232834 -185953866 -217282668 -712319420 -401805597 -543880269 -708855167 -865363604 -635804569 -916273043 -623467312 -280886494 -40764092 -446572288 -534914628 -836407249 -905130961 -678951882 -608753071 -678614063 -871778650 -117766515 -636831436 -209439454 -525160225 -454657664 -609488003 -895477629 -701817416 -475025085 -549904165 -133549763 -299065…
Output: -17600841

Constraints:

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

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