CT44553

The vials at Ashfall

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the ember dunes of Ashfall. Seth spreads the vials 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 <= 3846; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 3699 -494390125 -841951631 -332522510 -891426787 -553194534 -190209070 -799312123 -340783318 -440018919 -82967935 -223454794 -751830811 -347189720 -451779022 -507349984 -238335207 -674031157 -588968621 -290376555 -320311507 -373557987 -668192963 -975879843 -660219839 -225700121 -914360833 -101627482 -357437539 -861364888 -317308953 -844047223 -599964465 -660268280 -454225006 -436097901 -566943832 -805075394 -200253952 -908611794 -325219226 -185580406 -470525540 -898970179 -540267788 -793722790 -668723181 -250330649 -172498434 -110556645 -730007092 -962833208 -489318146 -327428168 -182591400 -78216820 -359403133 -545270842 -987801922 -304242506 -185845043 -887617241 -476974950 -770141305 -610249477 -376574056 -255454934 -676586335 -768693969 -725787796 -789998122 -539679910 -885109323 -7791…
Output: -494390242

Example 2:

Input: 2121 -231403976 -582397224 -694881656 -220325452 -485830990 -141940778 -238067214 -750028894 -191048212 -445028718 -575914467 -745976077 -824066873 -230738539 -422466463 -804947759 -40707989 -683494948 -565083577 -365372535 -983311098 -389485320 -817142957 -965785758 -711115378 -413276107 -380739133 -523161174 -518668578 -826233628 -331434742 -764096620 -434720404 -716977133 -52613074 -771268122 -737155175 -915113716 -978385580 -744499478 -854636403 -628808699 -715168621 -15937932 -647199284 -874168563 -591615138 -237975924 -31776001 -145508772 -997997921 -619144612 -607510646 -560021418 -825122658 -244774237 -60534263 -15151494 -56074598 -937594565 -134353852 -987638106 -702415247 -179039886 -634920981 -208575190 -964948512 -140053020 -214649962 -700512341 -212509278 -766317979 -490999949…
Output: -231405213

Example 3:

Input: 2527 -593454260 -920416618 -845729564 -101334889 -553368793 -362330157 -540315321 -306245660 -932107573 -482779016 -298392702 -483693425 -90379203 -730046540 -853226372 -367852329 -430744365 -808900895 -905856879 -488742901 -871227371 -838673651 -823597152 -732234872 -104060205 -130691018 -45520452 -356971353 -737702187 -48604530 -873462308 -771663986 -217369792 -37172671 -515224842 -444368277 -793172666 -205172611 -863716036 -8519988 -964703286 -96576065 -422394569 -243777770 -521162388 -465990279 -939378819 -781138437 -694027473 -128415438 -436013273 -401761162 -856701215 -952964259 -750316606 -532532564 -370182697 -28725009 -828776611 -236810088 -737344737 -400561044 -281772331 -954309763 -792212775 -94373995 -376197387 -747804796 -438695935 -489784064 -52566902 -370614519 -284079173 -9…
Output: -593454249

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The vials at Ashfall - MEDIUM Coding Problem | CodeTikki