CT55052

The Padmore Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the lily shoals of Padmore, someone must chart the migration season. This year the task falls to Cyrus, armed only with the shelves register. 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 <= 2065; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 1450 -910243 -106531 -688963 -139154 -412431 -583602 -229689 -906123 -735894 -467148 -70181 -826369 -607729 -882891 -547647 -744053 -71944 -597922 -580619 -35683 -157067 -422166 -330702 -470973 -688964 -509414 -211713 -715153 -533203 -251474 -350096 -538509 -357084 -628676 -878255 -976673 -95466 -605652 -150343 -63356 -284651 -343220 -669443 -798951 -381893 -837974 -406382 -693046 -485592 -237997 -934896 -261359 -122045 -895259 -44380 -779492 -252567 -273313 -301343 -854425 -764109 -770641 -15842 -200160 -601883 -824836 -555535 -792851 -345626 -548204 -552504 -949375 -363278 -245242 -189233 -867662 -846873 -284729 -65584 -571080 -205159 -995645 -896043 -933288 -768775 -395405 -11678 -683380 -656197 -285026 -640049 -545568 -260445 -644349 -810547 -976191 -399156 -162680 -340467 -831403 -923…
Output: -910243

Example 2:

Input: 1129 -956843 -944028 -59369 -200408 -97128 -234428 -809142 -6030 -626023 -575628 -307525 -627343 -123091 -644719 -793549 -984716 -710552 -319767 -850774 -985575 -235203 -505977 -796689 -677566 -865154 -711182 -242053 -843480 -559510 -927435 -50960 -599471 -490192 -977264 -196391 -413384 -24951 -107996 -244548 -257621 -554396 -80241 -986934 -80294 -676227 -692045 -410561 -82721 -127238 -750976 -554534 -142129 -349060 -969483 -259427 -43016 -312409 -875137 -791742 -743010 -686131 -222062 -373751 -987261 -948447 -866265 -300457 -83913 -856120 -595506 -994808 -363705 -474183 -783537 -493597 -183378 -750001 -119106 -547553 -658894 -54638 -500814 -434568 -911459 -356219 -759812 -117382 -363259 -9356 -197886 -488183 -32683 -589777 -814165 -142780 -726412 -66340 -792060 -38231 -828998 -958734 -809…
Output: -956843

Example 3:

Input: 856 -18938 -539419 -16556 -671085 -685734 -219539 -497666 -715375 -472599 -96484 -503457 -48412 -127296 -199848 -801655 -986607 -48837 -370884 -540739 -668102 -191499 -354798 -141770 -716910 -591560 -814857 -975729 -259821 -826216 -528694 -7329 -839928 -219669 -883145 -462542 -274489 -506624 -487732 -224452 -854018 -802804 -836421 -435510 -476744 -185432 -299496 -781339 -727704 -630146 -395015 -156347 -712003 -861550 -293665 -387107 -252707 -249573 -666558 -54649 -185657 -184206 -126376 -764396 -282786 -765914 -108591 -652759 -54651 -845625 -888122 -607423 -68464 -447870 -639730 -936870 -944051 -177436 -903375 -711811 -720849 -670744 -357161 -601092 -54885 -285036 -649315 -792086 -657180 -50338 -922014 -62030 -254555 -407771 -40738 -962030 -44051 -629304 -313980 -832617 -341597 -349716 -23…
Output: -19155

Constraints:

2 <= n <= 2065; -1000000 <= a[i],k <= 1000.

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