CT48963

The Argentium Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Quinn inherited the mill at the marble forum of Argentium along with its curious bookkeeping system for vials. Time to make sense of it. 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 <= 2472; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 2014 -472212 -450746 -177029 -907649 -163793 -166864 -281667 -793654 -330497 -676664 -322820 -568006 -437899 -305506 -486374 -527496 -940014 -269097 -695211 -932185 -377019 -19842 -188522 -678082 -338974 -456300 -827117 -319451 -37910 -69478 -537646 -205645 -624771 -887601 -683292 -667306 -970958 -166015 -325170 -662472 -281851 -48165 -1495 -332889 -192537 -882900 -121251 -933553 -275827 -190042 -627016 -270702 -898903 -858563 -747194 -982134 -145916 -27505 -198739 -73015 -252271 -91916 -538391 -68663 -669750 -531670 -71035 -556945 -119076 -208862 -25928 -352350 -619219 -884881 -67534 -753440 -852919 -411977 -284162 -115288 -113559 -251796 76 -839 -497767 -457801 -194459 -892989 -801247 -658329 -697138 -342510 -56146 -584257 -209503 -22990 -660233 -631363 -139189 -831896 -251191 -522423 -6…
Output: -472213

Example 2:

Input: 1985 -601482 -131379 -780485 -884300 -413826 -428703 -82247 -972745 -349665 -898156 -175716 -394233 -393227 -356949 -970996 -240149 -625122 -99491 -43005 -578697 -830006 -185300 -638548 -387789 -311690 -47779 -127579 -493943 -81626 -501886 -410945 -627767 -581266 -358528 -295845 -539493 -749375 -786966 -695680 -341940 -39379 -784644 -657859 -950892 -328953 -132051 -410566 -538952 -160014 -366413 -918419 -754941 -264782 -293056 -84672 -645639 -827463 -797059 -606731 -305070 -991336 -801999 -285835 -449171 -378131 -913479 -555305 -145365 -952389 -403844 -938739 -301273 -30254 -343771 -929589 -271959 -81103 -298442 -329831 -736680 -283183 -389015 -863264 -451509 -595403 -532995 -57126 -662709 -620902 -769697 -415249 -410787 -205768 -304909 -859834 -316878 -964981 -244019 -542905 -979044 -6483…
Output: -601482

Example 3:

Input: 1493 -952869 -210199 -825950 -714417 -602424 -284903 -822262 -108602 -182360 -973899 -149172 -37680 -665323 -548774 -239492 -212792 -150715 -42136 -446652 -563828 -649877 -757342 -793706 -587640 -459294 -983200 -995809 -244658 -419047 -979856 -243191 -361879 -925199 -973482 -791944 -495321 -879440 -935944 -48012 -772088 -134992 -400058 -559441 -884642 -11582 -87365 -965592 -810976 -890044 -68093 -758629 -127776 -777447 -344623 -825315 -469881 -588073 -468555 -496869 -167303 -504773 -510032 -302797 -536280 -705172 -232179 -697052 -43806 -130137 -357337 -503005 -709296 -377327 -256876 -54600 -572504 -631457 -428764 -211403 -311622 -710611 -80609 -30304 -365300 -677140 -133745 -232925 -786798 -353515 -484553 -95346 -322082 -851445 -688682 -199162 -16612 -914132 -781727 -601212 -971518 -207354…
Output: -952870

Constraints:

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

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