CT56756

Iris Counts the registers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Iris inherited the apothecary at the trading post of Goldmeadow along with its curious bookkeeping system for registers. Time to make sense of it. 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 <= 1144; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 568 -771434 -403689 -254849 -81804 -38172 -325281 -848754 -559191 -859332 -386799 -231507 -163867 -753226 -196495 -40811 -330691 -105762 -469434 -877552 -416603 -319626 -32637 -234609 -578523 -63627 -190236 -609422 -997915 -516269 -985326 -637627 -47716 -641042 -189570 -374547 -758166 -257011 -588597 -348398 -661223 -15772 -20553 -24929 -837384 -953335 -615407 -926011 -692016 -209604 -380615 -243834 -319762 -165507 -834612 -497880 -339847 -115519 -326606 -569760 -924334 -314447 -996437 -666857 -884388 -19446 -624952 -427872 -645296 -531761 -483203 -879065 -809080 -211398 -35348 -244408 -190438 -252651 -282180 -396092 -602968 -687185 -936869 -451313 -521347 -565411 -459281 -777154 -829660 -646021 -442943 -325101 -414980 -337821 -756923 -225833 -590119 -770521 -433321 -351501 -832931 -551905…
Output: -771435

Example 2:

Input: 670 -382521 -44060 -333494 -699373 -576245 -566761 -442112 -617716 -973671 -36429 -152462 -329135 -672177 -745384 -743685 -599237 -17031 -713 -925040 -245801 -304026 -530671 -928579 -492177 -675407 -248348 -870021 -22256 -683904 -826158 -350995 -110367 -650223 -975492 -713645 -202971 -317394 -723740 -181606 -24388 -597920 -762997 -996801 -347133 -239871 -674902 -982773 -452042 -437315 -205460 -735700 -620034 -873976 -162067 -34200 -49952 -723445 -226115 -805787 -243286 -695307 -524820 -166528 -574687 -633036 -183722 -92261 -643707 -218493 -801350 -564159 -574128 -322880 -451769 -199534 -68583 -318362 -745825 -543525 -405333 -177398 -750909 -132205 -290035 -531529 -34382 -783499 -955715 -31069 -705592 -30931 -79040 -285108 -181203 -221557 -443111 -810172 -436550 -851189 -240939 -704474 -807…
Output: -382518

Example 3:

Input: 674 -681249 -210171 -394738 -908030 -227921 -493231 -666914 -478402 -434242 -465598 -568360 -565701 -529889 -94733 -604990 -710413 -671712 -308148 -662697 -302837 -999525 -2454 -749325 -196057 -532982 -298167 -664503 -667876 -325987 -293936 -685392 -450888 -318484 -27895 -806782 -739596 -481147 -277801 -345700 -484467 -513485 -623044 -514413 -954533 -103800 -823073 -901475 -261358 -331809 -199248 -453830 -901291 -573973 -253988 -36190 -57505 -172921 -660501 -869157 -482151 -466364 -898119 -508806 -138929 -92577 -3411 -446599 -36083 -571371 -516157 -968338 -776690 -440849 -219351 -283142 -177525 -238426 -897843 -159629 -506648 -598652 -266406 -185464 -152670 -622689 -998129 -239048 -808108 -902555 -281542 -965552 -799055 -372931 -229074 -537919 -356689 -139482 -727467 -324435 -119486 -35889…
Output: -681248

Constraints:

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

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