CT48979

The Nearest Pair Sum of the Sunlit weights

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Quin inherited the fish market at the alabaster quarry of Whitestone along with its curious bookkeeping system for weights. 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 <= 3589; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1440 149607618 -87372637 833928120 263956003 964083807 766407477 318219927 212716244 -987999267 599279268 -454158506 750818864 -441416644 -334715334 711566538 -466053497 -906104096 -335142199 628849093 318902486 918595139 395408135 633393937 514912819 -412582917 500415035 -968340305 -14820982 183101734 137227856 282056410 112429895 786966268 -786040210 -409793322 95430158 -493065009 387505730 -65113451 391556529 -965983929 558093732 696298608 15821497 -5754591 -415833681 641752131 -729690081 -359542195 382734527 -955636887 -275480100 590573245 876086875 -722028159 -939396649 504985184 65156002 -859507161 -991141145 933737513 -919190797 918358540 -720272058 46426278 87511599 324804361 -751247608 -227308966 -458446280 -924322162 55039784 306501416 863598869 174191687 -322372029 -684114929 25…
Output: 149609580

Example 2:

Input: 539 1703139137 -887327716 84985611 -919951207 -858923495 369108995 945688041 335631374 -516944981 -868139049 -993517235 759123591 -867679226 -67183366 528698730 -804138849 616300965 -987363315 783541043 739574605 -202728521 53077362 62709606 305281053 -147266009 -516513825 860019934 -364807678 -779620626 24017262 -98402974 -977781851 -222615378 -866740324 -545913661 983200397 511320508 172195943 -18686318 184803104 23880807 -552584787 408314495 -842507452 -906689261 472924792 -492389134 58270793 -642358894 409225258 -632285653 186518808 131692549 -432355332 69472061 857249039 327651968 303674534 196077833 13445248 -509381561 417413802 -371838632 -570839639 637485223 385050618 -591034869 243616521 -216924540 -773803506 888422447 -610148907 354431823 447241943 -666182790 -734538188 699173777…
Output: 1703145851

Example 3:

Input: 3354 421494786 995140875 865097671 -571662088 500254016 40126275 -644553078 -247345527 414709286 -664624463 -739893589 -566545788 793393475 -105580868 -670362118 -33026729 360354452 357865039 837007802 262551795 856678222 540936152 964226283 -797421971 -192131865 -55673771 643128804 -426890113 113765987 -575350076 -782295048 9588920 402811986 326596789 779214380 -655140605 -965770127 25585294 -653726822 -838799105 861274918 -101113421 -247239600 -650921608 175326087 -896443700 148966700 652410072 -823707437 547773433 40657426 967846582 81473070 -466189226 -411213247 -490056061 -432238590 192272739 91463418 60266827 -981340089 -78082942 -476164485 570972410 490438601 104536489 -367302168 657067252 -729435127 -275317278 -722553617 817403107 186735269 -321270669 -99098081 223044656 740022005 …
Output: 421493751

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.