CT46135

Iker's Ruby ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the lotus ponds of Tranquil Basin, Iker studies rows of ledgers entries. One clean number will settle the guild's oldest argument. 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 <= 2784; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 637 -584906156 -784940907 -465084635 -811717619 -866180705 -555240733 -385446029 -265859539 -722897160 -690336843 -429846936 -763829919 -915319531 -127506119 -881387097 -782939293 -162961488 -804148878 -448909641 -227336818 -729314447 -803948026 -771107875 -274173823 -235027914 -192104729 -72134848 -879665606 -302107607 -81908224 -894527504 -226094819 -158642787 -499781959 -896876996 -739349084 -651457467 -935894820 -328140590 -719539002 -803368860 -717163152 -909853305 -688797872 -394375102 -330329619 -695105089 -998073545 -978982643 -694883566 -469041256 -781270572 -999047370 -243644135 -976674353 -627662658 -568609871 -268588112 -444829842 -863449833 -586055967 -287077177 -136046956 -395591985 -446667864 -990458528 -647888207 -331407585 -471617836 -736021143 -990182529 -500362961 -25960…
Output: -584905241

Example 2:

Input: 2097 -204360740 -720919895 -336862269 -937585944 -6276387 -859512100 -235660962 -198743805 -328222925 -601468806 -347601735 -239788113 -384816498 -896703414 -308635227 -97014339 -557797637 -257826639 -483367360 -355119022 -223020052 -964351028 -789699862 -255305346 -105978009 -166528727 -529345733 -325388142 -861421876 -505922435 -674022107 -506376016 -457254664 -911737043 -405643099 -963472458 -109282352 -513861813 -128330204 -850835766 -335366202 -904008128 -247653023 -398246179 -575805656 -656054106 -379586388 -225676640 -913980767 -5964470 -262788364 -530014815 -202098000 -63465577 -269606497 -134436320 -793333653 -389128862 -157331537 -956792775 -566771538 -173790927 -573146544 -427464922 -752245574 -834814789 -778375407 -470208971 -917019052 -655561936 -777571527 -759801626 -65940072…
Output: -204362861

Example 3:

Input: 2354 -939234666 -727530533 -670228442 -439724505 -485056682 -751685240 -848104548 -641936522 -273463557 -236518180 -443003492 -635832527 -955341543 -583161253 -608098093 -93754895 -56741298 -327085453 -672285176 -61061449 -568384615 -642352444 -256748318 -797221463 -359428560 -321656628 -826587644 -792152270 -811682095 -460430184 -287437700 -261761820 -868570294 -141678221 -175328316 -371228798 -115072857 -736658677 -319367578 -590411736 -69821362 -827865010 -535463563 -892217689 -318526947 -241966738 -356920661 -64034435 -515986202 -791532250 -764699624 -523174796 -290532865 -235962953 -393158816 -88119440 -389079980 -440642007 -923237413 -967902120 -419603929 -36083164 -634932119 -653067199 -896584458 -929651678 -588384373 -822785877 -726159526 -349213222 -456831015 -50282202 -616327177 …
Output: -939234661

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Iker's Ruby ledgers - MEDIUM Coding Problem | CodeTikki