CT42748

Quinn Counts the vials

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Quinn runs the apiary at the silver mines of Lodebarrow. Today the books show a list of vials, and the numbers must be worked out before sundown. 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 <= 2087; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 1200 -48152 -6827 -370573 -378108 -725693 -951957 -404791 -280185 -745491 -362492 -53413 -210406 -988176 -275647 -39627 -721879 -568856 -6703 -80400 -516043 -563110 -298319 -338744 -635280 -519481 -359686 -308254 -693202 -361465 -707352 -126104 -631998 -20845 -640299 -141658 -59513 -354845 -966528 -542577 -728462 -154414 -715832 -150207 -61610 -494332 -893316 -72137 -773597 -569783 -511028 -42586 -66241 -512771 -754532 -491803 -250087 -542293 -391550 -576667 -630435 -802137 -789038 -546080 -68611 -654124 -20013 -351440 -322200 -652674 -726011 -4263 -685159 -386518 -661990 -1437 -99272 -80528 -38501 -718859 -212423 -98440 -367162 -253860 -747737 -691115 -867047 -795200 -336425 -94161 -16949 -8197 -814130 -44814 -937762 -299193 -343365 -723333 -821804 -293740 -762256 -650622 -744551 -715777 …
Output: -48138

Example 2:

Input: 201 -625403 -397537 -438325 -9950 -166412 -187217 -191711 -847859 -664798 -377456 -205983 -930748 -233688 -434585 -104536 -308903 -781195 -236171 -255161 -455210 -929920 -5531 -157301 -648657 -837839 -335309 -346771 -519301 -229117 -466857 -793078 -568677 -330188 -328234 -607276 -749458 -383221 -639769 -708393 -121453 -714787 -992391 -825934 -815247 -813182 -723198 -325056 -187956 -877191 -119113 -866129 -663995 -593353 -218032 -456751 -184790 -580480 -113040 -367159 -236070 -883057 -604645 -624451 -960081 -962725 -956849 -638675 -874547 -444628 -951851 -237713 -150413 -901798 -193328 -749854 -421652 -230316 -492627 -302487 -572041 -697464 -109743 -863385 -292467 -37533 -238151 -353466 -570151 -224584 -815410 -217770 -679641 -355213 -35034 -377935 -453117 -669860 -810366 -321796 -917019 -6…
Output: -625327

Example 3:

Input: 673 -565032 -86035 -106581 -34021 -285049 -471357 -601858 -868308 -850158 -627227 -698283 -342192 -312850 -186844 -212465 -752522 -77447 -486713 -215654 -144791 -5464 -198225 -325840 -322602 -637420 -68111 -969427 -287282 -82527 -978684 -939487 -435255 -895075 -712014 -48756 -158747 -899641 -525974 -317986 -495786 -124244 -379711 -996525 -639587 -123441 -714484 -372848 -972613 -765360 -808843 -132951 -876075 -61566 -530800 -817517 -782769 -34382 -976152 -202883 -894905 -32860 -859632 -109160 -694597 -784407 -262460 -672647 -573964 -132657 -903912 -731144 -7926 -163177 -513732 -764173 -881863 -943387 -554013 -473161 -879771 -526782 -98109 -118255 -604547 -347091 -747441 -934172 -889371 -467701 -548159 -399014 -206122 -318598 -718092 -641656 -752807 -214766 -772304 -285605 -659691 -713639 -4…
Output: -565032

Constraints:

2 <= n <= 2087; -1000000 <= a[i],k <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Quinn Counts the vials - MEDIUM Coding Problem | CodeTikki