CT45751

Ysolde and the Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the cork grove of Barkhaven close for winter, Ysolde must finish the ledgers ledger - one figure at a time. 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 <= 3219; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 1872 -183527316 -237197991 -260849811 -314258067 -505257955 -539644218 -549945007 -90974829 -635029177 -717627930 -619788778 -253928788 -80015808 -140505900 -430504099 -401864188 -11352164 -319939130 -407231084 -96144097 -340283989 -364246302 -767206052 -928161727 -475620892 -481455767 -371615927 -328929204 -522722526 -154632608 -118811133 -159119477 -297365370 -409767255 -695367817 -833973769 -841115137 -135399423 -44749969 -4300940 -193478711 -724287322 -249009354 -53488323 -729742406 -292418125 -374002651 -564459147 -596666087 -260201849 -518997986 -752993781 -930668695 -96612403 -294318090 -994466206 -343739605 -377999218 -583921741 -539841129 -772554377 -92971857 -758568327 -970007767 -225898359 -900321269 -640352804 -749830109 -463292778 -991169375 -719986993 -413346156 -313218299 -4…
Output: -183528387

Example 2:

Input: 3098 -797823034 -415500161 -207033064 -23209109 -716638465 -320702550 -949170064 -769755568 -124514250 -227895283 -137940502 -963953463 -394960667 -474785519 -210468162 -838173394 -421272620 -560527727 -934476506 -278136019 -505466073 -443230589 -402528271 -650345610 -392552931 -404618240 -385666928 -172351151 -1333287 -161461473 -643056415 -389427547 -501260868 -162328267 -192476471 -884924101 -173749576 -236008141 -170159854 -18845931 -500697131 -207001784 -9640143 -195921213 -207348778 -701485507 -469113141 -686961757 -469448255 -380329039 -400117415 -272398841 -934451682 -657296786 -635805402 -59529169 -787855757 -452114030 -386525325 -503698983 -49560632 -280810137 -854430360 -918659144 -610107380 -447943111 -634300881 -450046101 -59560234 -281168824 -66683505 -934055943 -479705018 -7…
Output: -797822881

Example 3:

Input: 808 -17916358 -625601905 -279862995 -989527663 -693050416 -535296829 -978428045 -724934464 -272831917 -283814821 -715340117 -455095348 -114158111 -156933730 -177571673 -736353096 -62217656 -212924366 -913385898 -3543024 -219315400 -703416763 -337001968 -193594373 -366677025 -510776159 -191324301 -510165546 -922856046 -785953924 -670172912 -158127385 -337403689 -817116205 -268038665 -851310196 -338391394 -832496629 -107857586 -836931994 -455173498 -844510578 -925940847 -616718764 -337637922 -338551114 -464312491 -332549238 -545134855 -561418285 -395412246 -217602778 -336569060 -227838588 -348634757 -244811099 -642510277 -861877983 -942846008 -921187114 -640325247 -567190125 -714678185 -272289553 -419762111 -432970565 -319051413 -966612737 -949114329 -394115433 -659120182 -326741841 -3690815…
Output: -17713163

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ysolde and the Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki