CT43119

Last ledgers of Zoya

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Zoya runs the lighthouse at the steppe camp of Horselord Plains. Today the books show a list of ledgers, and the numbers must be worked out before sundown. 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 <= 3874; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 3518 279732472 929072322 -466460886 405034598 681199978 -692840856 -665039222 -156415651 198228770 652504209 -477646320 8642571 830923842 792883942 154068784 836873793 299294539 130640922 -274732516 630693221 744861222 210045311 -734994390 -540276401 163782914 -253725867 16251921 -703647900 -284526319 203923304 -319308134 -249335296 -431841484 -235730592 -593992605 -56157743 134134941 -737093856 -810687352 281667075 784775033 719757520 636365507 -105705842 10181377 -584607098 -646025822 -210993401 -230126677 -106017638 -720814420 -335774158 -728844744 -286250982 -331665597 59130431 -683953427 -520599989 -699488006 190022400 32608927 -102536894 950101846 743993676 -728283398 864335354 968441790 -916433521 -746165328 -25606414 811375977 602923442 -203488134 144680214 126033629 61179006 71289…
Output: 279732948

Example 2:

Input: 1191 621479071 324217942 448938700 -986387776 -211496024 -657665524 -903066931 625573705 -732108289 -595144892 -761487169 -157570244 612015042 -406438 -5442300 -925240597 169697412 438739453 288778563 219952134 -694308209 65516793 97936055 111085342 -348079787 615616432 56180675 150762555 484984683 -114314811 620447173 -947703797 -533964520 657542852 934854059 541296290 841396559 571038244 -663490464 -483110761 -90988677 288705649 -899884268 -688778748 132792083 497464873 -902067989 995040388 -178196095 197685410 980190073 -629672338 -93237893 162657624 969712230 321001001 -868716103 253512317 231728825 -41625715 424359424 -372152310 114436774 623002861 -899660007 -854823812 -301468681 -228847148 222317313 -128266171 559227018 -843986157 -917619262 -508321785 -656556609 -357312411 43530699…
Output: 621474595

Example 3:

Input: 2831 -776775637 -896768157 -229833379 764290183 104293640 -900420761 563565846 -306350869 478935936 169658004 65946637 435503697 838749851 385872288 -213839540 -770054280 -12564508 -554102649 -19644057 -411608968 -948985404 284449784 21608768 603709117 493579225 -134947726 716243928 -234269915 -694178663 -147693198 -152091222 850195784 695476806 780132530 -825009954 603546636 6162083 -900468874 683443771 464964290 885463376 -150326313 -794639310 647285064 83063290 -931866417 738737854 -4860865 316237438 855836451 -829095962 290453681 -668500097 -354465235 772335140 -854365542 -627336065 727812422 -781247132 516153272 358117733 -995947025 -197132259 -682683799 625229192 925724646 -722082672 -939604539 548077301 500004390 780516454 329142258 -284897849 858167018 122017684 -72566678 693433179…
Output: -776775460

Constraints:

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

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