CT39479

Nila's weights Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the wren hedges of Thimblewick pays by the answer, and Nila intends to earn it. First: the full register of weights. 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 <= 1966; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 1165 -683951197 -178436889 -462029125 -968396929 -56079087 -324246851 -682825548 -309500688 -473358165 -65844748 -940749570 -629844981 -281734722 -85293375 -958808207 -111441290 -455446275 -509827322 -383459603 -41729927 -356466807 -855659399 -885266956 -953935245 -300626674 -633108991 -979709150 -573708041 -592188081 -293510755 -998325167 -176914639 -89570266 -321752906 -271164335 -527226194 -543519963 -55418555 -130885054 -713386112 -920941976 -511801371 -119727898 -802326190 -696878506 -250059729 -864267671 -788345486 -814551054 -275976022 -668924467 -297514831 -412980006 -68784697 -344824650 -818435908 -179990171 -510247925 -983707022 -538286759 -791665355 -226367124 -249362626 -984701974 -540474991 -153387865 -293018919 -889953375 -76330598 -516883905 -269040792 -296712706 -686928073 …
Output: -683950105

Example 2:

Input: 267 -45616078 -871855528 -519467833 -932871429 -780398492 -925338700 -237540278 -16755979 -555215580 -155719334 -837054373 -355064014 -628233690 -756768213 -845871849 -531936345 -307565286 -603746402 -96034163 -920056734 -968693822 -518989234 -112894617 -20038187 -985371939 -734131111 -117631926 -734822796 -689452129 -154018163 -102704649 -285904757 -498358164 -208062931 -59405095 -613401854 -420606221 -574559037 -344124219 -750519293 -124849836 -169603260 -418530721 -636524764 -424627040 -631441538 -222834053 -472379042 -142472982 -2927702 -314125714 -635973426 -973132689 -323393377 -764711382 -935098697 -813716488 -209542383 -796294697 -428434821 -551244920 -145217794 -807867844 -623888487 -143502581 -87432960 -354753080 -770849209 -401438198 -243809279 -876586166 -486431637 -752311471 -…
Output: -45450938

Example 3:

Input: 1055 -463866707 -668708201 -188076831 -739015429 -842418932 -35283603 -6226020 -405656167 -647243742 -506227534 -761189862 -826367022 -405895475 -653789491 -949902659 -814439833 -168072060 -674343066 -66463130 -896159614 -83521847 -686241977 -844945199 -4110915 -128424852 -276206492 -625955509 -782540690 -627413481 -801173697 -333041511 -704712486 -275475431 -402778881 -171800537 -769775595 -681597717 -637997446 -42075047 -167203439 -641745758 -742433926 -975299543 -656918896 -61590126 -104758487 -855658246 -875486907 -132588250 -669351547 -495650239 -500190272 -916015468 -930680265 -120867136 -511327148 -626226278 -295407539 -745793858 -512201322 -232034355 -957194421 -715808747 -609196071 -199934578 -96946768 -558530279 -51808819 -292486911 -962779473 -103530896 -557931724 -66107914 -916…
Output: -463867164

Constraints:

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

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