CT36824

The Nearest Pair Sum of the Prismatic crates

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the orchard lands of Applerun, Yash the log keeper keeps careful count of the crates. Schedule the next expedition, every figure matters. 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 <= 3569; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 2294 65740490 36415701 -327983395 -25006310 867248887 191691767 -730300079 364414557 790603503 895384740 861074268 -337597548 -771770144 -589495720 95742216 564056060 193855019 -147457456 912355452 643815479 -737831514 201232511 -346247566 -838305607 -356690418 199485564 -185340401 -125335162 -28614590 865542131 221989704 531592635 -46409966 -727663787 -689481458 -512107519 -535411536 -350137129 682387557 -204984070 957021001 731722348 168251485 519862266 -490078190 -292235545 445145373 -186879462 -178282699 273041021 -102394468 -801500237 200980434 -893572153 96783088 658061115 -742080600 -247332176 738301598 375061472 -404990840 -708030541 388218944 -573917972 -168711501 3793385 868449012 795595671 787506348 -680235254 491738810 -820586393 562494880 206647671 -804718422 867494763 5257398…
Output: 65740906

Example 2:

Input: 2919 459648343 15382468 998925223 -757035818 -403105110 672356086 641930299 512498685 -951858722 -940176390 870913666 -757653244 796333692 -397863934 277429309 -490861224 637100399 -213550458 622742409 620266864 629722235 -137953987 -141149874 226298355 -280319987 -731195506 633952211 596595659 784224330 43684292 -503991666 -543807516 -592419693 -722174144 299296740 668257521 -402643380 -276753512 -697288008 -309649889 20862370 976487878 235921714 336845142 -493520299 176077637 -318400683 269238785 -514574644 264298806 917903792 -406706665 8723846 -904992431 212464668 611312119 222056341 -116159692 875686195 -373430783 88896482 49133730 174288595 755393254 661853563 98685818 -380646574 -589822654 -627686837 51503982 -149212912 -138972667 474593855 317652196 427576081 558763760 439695960 -2…
Output: 459648172

Example 3:

Input: 1629 -252425158 -147976915 82371283 -38085283 -870175792 711340056 -538552450 -273504044 -924157375 -437693725 965229010 -276622895 -611925559 760049121 101662432 699661546 -336726241 -908064544 821404294 -782886500 148318414 707922143 264180186 360988025 182669781 877935000 231011650 -505954194 -344615991 -484318569 -14165857 816200182 176488022 -168871958 -812572197 -195284831 -287281306 -545563817 -949353586 -320518831 -945315909 -189922570 -460380155 321883582 -496884899 -322625249 870414708 620102577 -925847444 803953786 -611297526 71326079 235595889 532210405 262336332 -10644766 -69597068 -506534196 345977355 754676759 653667187 54796211 -96026908 211346568 196360384 333268886 824393768 -284875286 -927858349 -321275216 -879780450 -504906377 -96986470 488990275 -486072069 -988057813 5…
Output: -252424748

Constraints:

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

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