CT53340

The Lunar Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Cressida found an old ledger of registers in the tannery attic at the garden city of Petalbrook. The margin notes pose a precise question. 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 <= 3604; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 3408 1369405475 497679939 398345315 862217858 654116567 680048303 135756701 947101182 886471702 631699390 200065592 387190574 780408939 275253618 867364380 716635323 550422792 146478361 455421005 140441191 979388647 721945713 528218378 38448472 877668842 292376114 802386789 765139934 814553632 691213944 268012393 316099288 477560491 205606067 911526708 216932725 731162555 736934384 864249776 729362179 690804127 752863843 891643337 543135598 602673219 551228380 771359914 322329102 45556409 597079262 790394890 604166792 750560092 550115094 861794186 942201623 124985478 691242751 495957509 542810504 325850166 679559153 941423959 66892776 736555767 522662729 384402223 54622525 997063208 882438028 340568035 741441883 639868929 577041243 647585821 894881959 990628960 897185650 404776665 11228462…
Output: 1369405486

Example 2:

Input: 1066 171145098 524377177 751749760 597741479 410018916 897950513 669481372 236801115 100432138 614577950 221492341 143223729 936505766 920452963 968596456 550954459 967520850 684575610 30056890 106526704 271006514 268433383 770819890 118062718 416197581 903206622 643312856 798713700 2185721 150842717 10045722 168162600 455328979 290370431 761774501 658633604 466117507 1825079 134848939 409855657 454674127 708313224 785244828 949522409 932369365 311194577 197320578 922650240 536940103 140801579 41299459 777771108 877420626 85205852 784603962 15256679 296753757 607165590 981416603 267699554 722244564 248622897 431728111 302428106 932816602 11959884 483965913 315336796 615441953 453384641 541287535 715390558 372935363 821920342 794245765 712198053 621176371 285987134 866115477 30721175 376873…
Output: 171147842

Example 3:

Input: 2894 315495128 409302957 905519766 951031935 773971622 30949150 811173505 424995716 249427660 728535957 557656258 976254301 980618537 253142288 508466357 461962743 655386421 100369312 614715088 981549095 232209780 276861561 479215480 284416351 615185819 356172825 447271970 781961844 987987491 133421500 178649046 49747880 937215388 -240113 569155360 93686187 451941109 112763393 497730601 919127059 541086834 569390306 316667564 605200890 277785660 248228298 704565833 197545713 174956705 443281965 784079876 423356659 25787265 773538511 387879249 481859187 997600534 780246749 503467574 102799010 95878610 98623659 397630978 254337171 764652863 373838350 725323061 252066540 219691720 551921573 713477984 641654735 391702407 470043663 146452860 75874124 466746592 343133780 424133907 225737043 8562…
Output: 315493310

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Lunar Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki