CT47804

Quiet vials Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The quartermaster Finn has been asked to plan the beacon maintenance rota. On the desk lies a long table of vials readings. 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 <= 1100; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 235 -630564338 -159648936 -595711926 -571729790 -233169050 -599826705 -115744999 -868121981 -217752575 -37894844 -148001537 -857794438 -573090659 -131929919 -137324573 -167596238 -582563435 -49101148 -783177659 -846255730 -30132462 -169988629 -563169727 -275194370 -891721525 -136926055 -635861150 -567715854 -220266558 -717199711 -496100498 -839869610 -395173231 -52684849 -677507204 -254039606 -537132108 -398544553 -377049569 -117563766 -398673833 -118517815 -194240819 -306092053 -511895411 -159348359 -184706655 -312215165 -868774236 -962337878 -283384885 -291778042 -507434964 -806205939 -85021796 -837909212 -96831502 -983125052 -369547675 -928258423 -230322475 -20912913 -617051279 -614781204 -665471144 -940747296 -663255724 -13164496 -136868942 -258843751 -843187670 -609704193 -645453213 -…
Output: -630537538

Example 2:

Input: 261 -580398542 -182266263 -480215342 -892658578 -542030335 -445321671 -136654658 -8244516 -732466014 -518431995 -352732540 -78242927 -438265003 -937924599 -961596887 -61870331 -501935852 -91953002 -279554049 -728146470 -829739890 -159959507 -173463071 -249136327 -371920790 -589003079 -790933630 -845604539 -705538273 -798070825 -852412083 -572463643 -45396233 -949115528 -479347325 -215936528 -406936517 -380986343 -526762449 -193991413 -758697280 -621038311 -277111494 -352648507 -493341782 -16485485 -306921790 -42025368 -192676483 -551748245 -16953726 -946746166 -963559279 -545224291 -435126451 -415963976 -134704696 -527407459 -264823106 -669731828 -712049130 -29598064 -868520359 -453724628 -915048992 -499483696 -312922087 -466774302 -716717038 -891599010 -780223653 -676288502 -543676915 -44…
Output: -580399588

Example 3:

Input: 284 -176747463 -598180268 -831546900 -225569336 -689479997 -951365269 -863365421 -858973840 -176353265 -340509439 -2724636 -537932945 -268841149 -395028983 -767108212 -166142221 -654590086 -84051232 -776961993 -330827494 -671612821 -248692640 -675833966 -468602576 -461770780 -548039872 -310687004 -341110084 -757942044 -559050877 -581138699 -317158535 -610424138 -571530195 -741134800 -819421480 -667489177 -982136195 -612932713 -979167376 -604891996 -137149553 -461749331 -738304042 -865311754 -443195983 -97985951 -521819468 -90125990 -356984162 -695634480 -556734010 -973587484 -229381941 -532305343 -441511421 -535265714 -471182409 -720052610 -174538619 -705208438 -868165465 -885378914 -640465008 -447058691 -210937837 -722152181 -200762372 -558180895 -712430287 -700556055 -879168325 -53637557…
Output: -176702958

Constraints:

2 <= n <= 1100; -1000000000 <= a[i],k <= 1000.

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