CT42223

Elio's registers Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Elio found an old ledger of registers in the studio attic at the otter slides of Sleekwater. 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 <= 2772; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 2604 18148498 237979782 416825692 34852053 813129717 938953581 729059230 278193584 423855542 397037426 610651708 842094002 63237058 615624195 993878784 844291739 441332157 492939656 551304756 575924108 773115157 368508094 6063339 303814 102278976 522456989 67540346 383914582 622324814 467897028 954739038 897476823 411293087 497007678 38897269 246366272 316638647 893407730 831697995 306056277 383285863 -808735 400597875 623066166 615081308 960631633 488087572 31694969 45469225 95665006 551545242 579284086 659314132 687739184 782923039 447166927 359491285 -795141 229587841 636814618 678282237 43280056 625755602 843229359 254275493 56688675 249384703 706812537 852146439 611976482 194818907 626921151 467618125 458166204 366818093 372319889 242183471 352238248 28105893 992443216 757238492 50350…
Output: 18157118

Example 2:

Input: 710 977250243 144821775 980551783 866394285 812633213 892287370 471730854 709484062 976302011 350058903 162394099 165953052 435739504 727004211 781389916 331893615 350723859 601358790 423661848 916762855 132346358 353031319 967134286 472947285 127864897 162083064 623604354 454939690 893310697 612629321 592561768 23203426 292953896 548185542 311026442 104401154 148062859 346504045 951831474 377039729 758758108 72478854 104489470 856549849 700895266 902766979 534783222 355926211 667840565 365526557 370643995 7542218 763226278 351833260 555412053 400596894 647676441 497733176 556219379 974630828 604243437 296537268 584431359 297118136 437884784 514486008 521892893 681121184 542299516 390154231 755916035 75620359 79065247 362201354 833228228 893808914 537152381 170029076 540231558 706894268 11…
Output: 977250810

Example 3:

Input: 1185 1636762747 939025178 487662312 306068716 -800131 42241183 135883175 695541322 656544559 387448111 637831138 427394178 537002642 357837401 606299392 145212195 653347541 625899395 378349465 50105957 128882232 841087109 721396181 461220555 770953980 759215955 495556385 93045530 956392231 634183938 349351441 70450568 203996312 585587449 560856535 642710613 303981543 193080449 901628208 986012511 835167745 499948159 345040233 519078313 635284460 337448042 359314481 839465728 40232521 660950804 14607042 637346931 378842661 641721987 211102285 265352496 462864303 118986886 37911200 469754877 318294169 137061545 707612490 238107094 472045813 274328235 573706161 234034724 961723659 693378571 918762179 184680331 458148828 115691864 330192175 845671901 944589116 4903439 97927847 762375896 771194…
Output: 1636758631

Constraints:

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

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