CT55980

The Nearest Pair Sum of Caravanrest

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the dune sea of Caravanrest. Sailor spreads the shelves records across the table and picks up a sharp pencil. 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 <= 1312; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 377 -179473847 -787183021 -340355795 -496116332 -521532870 -487973171 -841268169 -224536548 -253405038 -674536094 -896101754 -493634850 -69902593 -812572198 -262546188 -96199615 -91145335 -795309271 -744263850 -12754953 -600864235 -783835914 -692299284 -39705098 -874181045 -517604188 -145158285 -60563230 -909751049 -462593905 -305325601 -70930842 -126236938 -83234533 -681023688 -460142148 -963227376 -131044974 -450023098 -567578572 -481282081 -980367169 -40038897 -970699848 -476337635 -491594256 -567973638 -742888782 -112186504 -717606889 -665603978 -934329440 -54752595 -235271161 -320980807 -476905626 -172998474 -122411602 -994208712 -751575362 -706400665 -346734306 -53358384 -61490067 -631501868 -559679917 -335670404 -795846026 -917229573 -242929860 -921487011 -891512818 -928613047 -4855…
Output: -179443506

Example 2:

Input: 502 -271725387 -254247346 -789872723 -199993484 -389269795 -149906519 -606932896 -874822414 -28946146 -326610703 -743441289 -865840602 -178376601 -85656734 -888395395 -145808462 -284367085 -934840979 -421919227 -676347279 -70722596 -148557667 -771619760 -485237296 -399085070 -628745551 -847956335 -216255325 -541271697 -785413608 -694698902 -703677019 -875025288 -453984065 -542778627 -356790426 -63021675 -396389748 -327180066 -460103724 -387792138 -329105176 -130964135 -99848216 -164411447 -416000610 -550323410 -362552925 -108502071 -440167845 -261176417 -241545376 -753615351 -431173811 -980684724 -972057372 -722456676 -883159882 -466893953 -544930463 -742761266 -812431986 -514545357 -169756091 -766946559 -125772482 -603483776 -664223740 -232844188 -864406511 -607387422 -465408232 -32717440…
Output: -271729113

Example 3:

Input: 1282 -152895595 -109205278 -296762488 -536128983 -364812372 -159748844 -894019953 -265371473 -714920309 -752975314 -202322361 -828045256 -731694392 -497148882 -943430803 -116309375 -772289368 -93421338 -864862566 -614722177 -670900445 -348834520 -51692912 -785188756 -416158241 -492766437 -979629543 -430467424 -526763264 -675232675 -645959938 -112741966 -198226502 -97022130 -809149522 -902540756 -476786453 -403537421 -225608764 -996668786 -223682744 -183575062 -574233668 -717023546 -221768080 -428480844 -728515472 -283540427 59849 -206210978 -250487947 -961346989 -352909553 -776142814 -127748842 -996704540 -191109823 -33548610 -68857660 -281614127 -601154554 -466454570 -690437799 -447802852 -427034340 -700594609 -793497915 -941243031 -353720557 -992891623 -673318407 -837607611 -716741335 -8…
Output: -152889318

Constraints:

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

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