CT48671

Surveyor's registers Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Surveyor inherited the cooperage at the pearl fisheries of Nacre Bay 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 <= 3560; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 852 -283452 -248494 -995438 -574846 -100376 -432549 -440274 -953903 -463165 -17712 -353436 -614858 -514264 -262868 -42448 -204835 -240858 -979224 -399091 -273584 -295983 -876924 -385897 -20902 -616507 -169209 -170233 -142994 -725767 -695719 -749610 -88263 -977267 -702399 -375028 -486252 -421848 -388606 -658498 -821286 -109200 -811527 -188098 -726576 -507167 -970698 -994346 -637029 -538451 -682784 -747837 -568869 -205944 -799630 -119465 -417850 -761450 -647603 -16385 -678390 -905938 -246302 -903413 -388600 -269276 -11210 -920246 -922952 -600689 -94931 -599198 -469 -907770 -900710 -436171 -713961 -137202 -138935 -597216 -474232 -183592 -628477 -711471 -960794 -581099 -216505 -679695 -637732 -331671 -872906 -765954 -957895 -910115 -298198 -278377 -588027 -912706 -345422 -766937 -171999 -22229…
Output: -283445

Example 2:

Input: 629 -803163 -418090 -591755 -276591 -915565 -653371 -762399 -721709 -354580 -53378 -487185 -45680 -365307 -456040 -964180 -986618 -242529 -757106 -305497 -799702 -375979 -815815 -691391 -442905 -649767 -763048 -982440 -78639 -189495 -973476 -603078 -523279 -233594 -958203 -866886 -304026 -259628 -410157 -282262 -934208 -118237 -335504 -887920 -145250 -146865 -98293 -814861 -504868 -334378 -325756 -619888 -382587 -895681 -933859 -833136 -651701 -48632 -852780 -336901 -647718 -483271 -686582 -366031 -312714 -261232 -236624 -20702 -645954 -297317 -127943 -437974 -783820 -536706 -132802 -979691 -6047 -157551 -333083 -956309 -135399 -444751 -354702 -620966 -318731 -500979 -829743 -187637 -831786 -96740 -347324 -722349 -446536 -852058 -226144 -475579 -977288 -711272 -643678 -763281 -371589 -6343…
Output: -803161

Example 3:

Input: 3008 -443705 -478654 -302571 -932098 -293039 -109205 -819688 -798641 -92607 -133598 -436824 -890533 -992344 -293182 -488480 -596075 -453575 -941012 -322993 -785450 -216478 -593389 -585299 -765757 -349863 -349729 -149791 -895925 -64910 -707119 -774338 -562997 -964520 -4711 -673456 -909587 -488352 -738794 -704012 -146414 -246925 -114884 -179352 -477920 -861787 -57322 -770885 -899489 -205741 -651809 -736466 -573684 -504482 -771048 -937266 -647750 -753076 -947372 -470043 -355239 -294294 -765465 -378571 -124560 -469232 -192364 -831207 -683000 -555879 -99912 -344423 -834536 -563223 -225020 -547088 -766136 -608717 -318293 -110558 -959775 -275975 -712371 -470679 -778960 -539437 -95677 -200114 -100972 -388467 -95217 -387770 -320353 -700028 -361355 -771542 -877053 -781677 -707100 -584516 -91415 -113…
Output: -443705

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Surveyor's registers Reckoning - MEDIUM Coding Problem | CodeTikki