CT55646

The crates at Firefly Mere

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the lantern lake of Firefly Mere with crates of crates, and Mina the clerk must account for every last one. 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 <= 1398; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 1364 -734868433 -939325783 -209114508 -16589827 -767408219 -159875567 -863484297 -210452295 -651976487 -458595717 -951495531 -683743758 -71935268 -388539435 -97222154 -562670128 -930729385 -153022239 -81560741 -777412005 -475069298 -386837118 -709245605 -668129741 -868021611 -983436171 -548485028 -402082074 -334134297 -188284576 -606580563 -926173728 -198004885 -633932678 -322077543 -689988963 -924408103 -622249865 -119059302 -342760578 -580770186 -363864407 -375260527 -808526520 -483943452 -458343643 -563479496 -815294571 -4209648 -26641508 -459948369 -373614605 -821743512 -963208833 -469661409 -13210065 -601927252 -323093346 -621151028 -645940479 -522457328 -679113313 -900865369 -652065261 -604444480 -707764106 -361231657 -648381765 -715764236 -968843902 -800364587 -327673122 -851625971 …
Output: -734869716

Example 2:

Input: 1381 -542504395 -300229426 -510012370 -842694493 -733988737 245799 -123426239 -569550972 -162741752 -217911534 -944451309 -996404369 -311019984 -274466569 -442019928 -558439 -515318065 -636087558 -186643395 -514887289 -847875361 -752221478 -130450349 -868950385 -466442848 -91404888 -334286832 -967075458 -42897368 -655225587 -142552923 -885576822 -62148007 -816863622 -71796939 -784758937 -461439560 -968910496 -864110626 -365961644 -117811490 -945042200 -642790002 -693826824 -306950324 -306155620 -504343714 -69132720 -908755472 -688987629 -99202452 -914363867 -188385062 -857798272 -346070391 -244854971 -361035047 -110900102 -202051298 -394964327 -784905396 -667795847 -603989322 -105172406 -938938194 -830784032 -35020321 -55886980 -607454830 -328306724 -626308063 -102745939 -31787604 -4463984…
Output: -542503563

Example 3:

Input: 345 -224599167 -119447832 -234709370 -130489208 -850691725 -457153746 -174994828 -305638028 -327383210 -384692637 -735696847 -735299511 -440906779 -972105606 -122217714 -39968010 -251473907 -312490405 -687820333 -851269626 -621208515 -129709486 -358040190 -389929289 -699323198 -522727564 -84788664 -900101523 -687343965 -824087441 -864399468 -693102698 -626470054 -418204403 -545414347 -970032794 -500336273 -265755768 -19636070 -75013223 -35738314 -686369254 -525118391 -823106185 -98246014 -338797486 -99300991 -849083926 -354123795 -21381753 -624257359 -608448624 -852551998 -964197697 -243093721 -10640997 -351417355 -541661644 -192692152 -339158313 -117574639 -622283781 -188349275 -65933646 -141907182 -189426285 -59445259 -79611702 -393978021 -144953570 -149441295 -512967898 -192439204 -1773…
Output: -224607396

Constraints:

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

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