CT53903

The Nearest Pair Sum of the Brass crates

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Xanthe found an old ledger of crates in the workshop attic at the lily shoals of Padmore. The margin notes pose a precise question. 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 <= 2826; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 2095 -75553784 -757647310 -353392088 -880779875 -232635189 -680260856 -393495385 -345500306 -779211427 -399670196 -794184813 -384511929 -699381400 -672276621 -278971829 -351385052 -203759439 -92297625 -715527400 -825789555 -619254999 -668281994 -446682785 -765752427 -579699327 -582355827 -600729860 -549184866 -692996868 -512784147 -933405354 -466413521 -450480149 -124345652 -662605312 -980091796 -546744170 -510541625 -633940635 -515841542 -689711059 -556430672 -295383485 -828167496 -528889294 -279851350 -681935060 -30086430 -937682697 -528517071 -609326496 -418037015 -416439402 -90212161 -415947576 -334456601 -15737345 -83595170 -519574111 -934274980 -133121435 -33643416 -515567545 -61107896 -75402870 -560903765 -201235359 -805283938 -960848243 -532533462 -467942222 -126959149 -587445070 -…
Output: -75555910

Example 2:

Input: 260 -949416944 -3980327 -169273365 -209720507 -437146295 -198653229 -859983458 -128632563 -761196273 -688246834 -356051325 -862158281 -217375260 -931239752 -558586758 -668589702 -787524770 -450985712 -833964571 -785575618 -133713013 -727603357 -274521553 -14748734 -297368734 -202183197 -166722449 -95042995 -319468372 -120086220 -921831716 -965094784 -692887470 -763889963 -291141182 -250809212 -495863932 -863173316 -65506995 -209186564 -457166526 -399634895 -175493294 -172724288 -518739169 -640144707 -999312936 -411467530 -697300595 -668223633 -505101758 -149141297 -885231485 -273576966 -860331124 -565698693 -828035237 -944844778 -849983291 -440245636 -233461337 -673359489 -418948171 -490751945 -325533008 -782425016 -498248046 -461459449 -781903945 -332232227 -247647229 -357792639 -12813931…
Output: -949414830

Example 3:

Input: 1751 -697033577 -748333521 -263517534 -959356374 -883613072 -288044139 -871797814 -51477407 -632910940 -689564751 -881229785 -830530602 -234956484 -937889504 -779611321 -99430546 -623681320 -562550259 -959514684 -139824497 -314878798 -507966577 -726307248 -585748671 -309168747 -474873987 -400662762 -893879100 -142578236 -740097271 -213295587 -945903414 -795389254 -185011281 -883105661 -597605581 -673250632 -488326840 -484172562 -337689776 -667441192 -784224910 -19579292 -831347621 -275843980 -492125413 -236918598 -999310393 -111861323 -397092591 -1973015 -132811014 -143583071 -643375271 -359150416 -500352251 -821360492 -347998068 -689359262 -353115889 -790205355 -687322282 -921817652 -678804029 -374467792 -191659086 -282019888 -213049297 -801372115 -189973497 -192021846 -496479609 -7827847…
Output: -697033492

Constraints:

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

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