CT40625

Amara's crates Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the cork grove of Barkhaven. Amara spreads the crates records across the table and picks up a sharp pencil. 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 <= 3964; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 203 -411481879 -896745934 -289836487 -180085607 -41649130 -690306163 -696913987 -895598052 -424258011 -341169540 -342662229 -867629449 -824688808 -970419022 -457346176 -35519581 -361486678 -77431873 -845509952 -286278138 -101676077 -41054074 -311530017 -110355075 -229877503 -490280224 -983000638 -604246442 -634405057 -846610841 -758044732 -153459413 -846178356 -586120105 -300645180 -984629867 -957054819 -577721916 -47804154 -587329159 -415672378 -415068386 -239873368 -210668224 -706281019 -729406875 -846613695 -192830883 -625664533 -262568290 -666417180 -113820682 -423065404 -335683345 -433034621 -30588852 -451094001 -626101091 -801664589 -942063975 -50298087 -486914441 -542193550 -231831036 -482888197 -980497619 -562276879 -715111137 -732691686 -82224994 -284827731 -856999683 -922548645 -…
Output: -411495483

Example 2:

Input: 2814 -4831244 -982904674 -955795900 -90996571 -221540272 -99149827 -287899563 -31614349 -61403031 -787927440 -655521834 -405289394 -701997245 -752974305 -318829216 -847871856 -739977945 -905056860 -631479418 -879936420 -167972250 -110447263 -802270109 -633707376 -401893606 -645265420 -931263725 -819676294 -431090764 -732180732 -900992684 -801771265 -771449661 -164730168 -833891015 -571979236 -982788672 -441243569 -720404775 -684052984 -490274546 -472964596 -800853928 -433044038 -297211291 -144942667 -121160078 -620757922 -333820958 -190825971 -25796295 -413639551 -48911881 -423135050 -572071551 -590101353 -71885936 -493128673 -92526270 -682406970 -620676998 -543132302 -564714988 -269883890 -593269218 -704970718 -374636991 -894912966 -200233860 -873741968 -827593040 -197025596 -664284990 -2…
Output: -4830715

Example 3:

Input: 1900 -111124665 -853056721 -596499127 -269494844 -891796613 -450035827 -49787420 -137165325 -12468108 -958885839 -226772808 -925259734 -684768792 -845216481 -598984054 -560958785 -809538544 -184149457 -430770045 -651341870 -780931795 -429319464 -827426407 -876265444 -519835420 -981336744 -650613406 -460792659 -649657319 -791675508 -759704506 -48547039 -748895587 -623152409 -488794030 -959812607 -210328936 -957686426 -353907559 -404688867 -48854778 -451834569 -966591658 -985672450 -312348860 -863433754 -803711339 -583871186 -470459946 -874988253 -909481005 -143592444 -682135840 -889343778 -695281907 -629434840 -846363003 -328835381 -438142663 -393439773 -486312629 -505603731 -684735570 -875441397 -829072482 -523366782 -402296635 -753483227 -506067287 -590992539 -233184451 -975508654 -181049…
Output: -111126552

Constraints:

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

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