CT47887

The Brimstone Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Nico the registry keeper watches over the sulphur springs of Brimstone's stores of shelves. A careful computation stands between order and chaos. 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 <= 2011; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 440 -522248 -745548 -713545 -953621 -419275 -813907 -227526 -2336 -296656 -289214 -860092 -628498 -8036 -895159 -75514 -583042 -413758 -228911 -231233 -911949 -17725 -296595 -347306 -907203 -41703 -898016 -43888 -593707 -793032 -6884 -516638 -192655 -151421 -889398 -4467 -256509 -300498 -771622 -474300 -172973 -941716 -423126 -106408 -40284 -469740 -846360 -209836 -538044 -127821 -433052 -300803 -239162 -593213 -622341 -326304 -626174 -749465 -124780 -283982 -410971 -825248 -694284 -680638 -395746 -201856 -618659 -922502 -337017 -165109 -386694 -388810 -385277 -835468 -24955 -333114 -981873 -698247 -823745 -214037 -312083 -772918 -651323 -283178 -690749 -676210 -822386 -859501 -700701 -926059 -641746 -61942 -104817 -360150 -238333 -334080 -182443 -836133 -819082 -27461 -660811 -664579 -406…
Output: -522248

Example 2:

Input: 1059 -401145 -21050 -331187 -345414 -755327 -457075 -445881 -451720 -258050 -832271 -901819 -691026 -740679 -331022 -472868 -373434 -968763 -708721 -768081 -22044 -563602 -398578 -123920 -394256 -477610 -136237 -225390 -855041 -539687 -243816 -142496 -848851 -443823 -295896 -895601 -145348 -825862 -508284 -681729 -564949 -94618 -51291 -479086 -530097 -565132 -426452 -38145 -58553 -926585 -333165 -925583 -28643 -496430 -57248 -450793 -317301 -50323 -921843 -31959 -268624 -595639 -819292 -777181 -132999 -429666 -639350 -863258 -309359 -756118 -588157 -736486 -901956 -521002 -168146 -57807 -28268 -724454 -639616 -586996 -236438 -185829 -324230 -594826 -124285 -110064 -532892 -448757 -92717 -489607 -692700 -205380 -577562 -110788 -205450 -967529 -847613 -465624 -137303 -622587 -298788 -633647 …
Output: -401136

Example 3:

Input: 1836 -315804 -785613 -211652 -609238 -835200 -450696 -597256 -873441 -210598 -700874 -873915 -3635 -97233 -980586 -575842 -424968 -151228 -801481 -705719 -238497 -855864 -334838 -235733 -84283 -326452 -478027 -829956 -586717 -82627 -964505 -690698 -220047 -459034 -869905 -409205 -42339 -76739 -92406 -467062 -669479 -351076 -578233 -677459 -13946 -854730 -614777 -33789 -766662 -103986 -899838 -305913 -484322 -69676 -832405 -653233 -335220 -267750 -329211 -347325 -878386 -399476 -168191 -245881 -178771 -623749 -184068 -283612 -220002 -283588 -459873 -754749 -144409 -205932 -115115 -639435 -321605 -29488 -611869 -974312 -660755 -975146 -602477 -938776 -862900 -313675 -266018 -22310 -419715 -466454 -625306 -940576 -788779 -906033 -8951 -614911 -586872 -544503 -849033 -266819 -142581 -79452 -51…
Output: -315805

Constraints:

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

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