CT51085

Last shelves of Grey

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the quartz ridge of Glimmerfell, someone must settle a dispute between crews. This year the task falls to Grey, armed only with the shelves register. 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 <= 3171; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 306 -85094671 -846740725 -468195925 420909978 -238849215 -75737790 579335435 -601942560 502719697 -660046267 -103500118 -136055437 -368128061 529600589 -563968061 750792629 450305169 -418760732 395143044 504082755 472161638 -511007757 782326132 -220490947 776254328 857158200 -190779112 180997217 504705829 82692094 211873236 -58427110 263541908 -501083505 903418217 94092537 249455340 -975092479 986592398 913863462 -613029684 839498242 69937562 926151328 340409262 -938767115 18234198 -428172692 -824007336 -945207903 977056224 -853348076 818802471 -53330687 178279847 2961407 211086721 -467997692 -299367232 -939455304 -997148607 -638595771 -48873112 -235857102 -426595574 -453269668 13045524 -95579770 -33123232 130100657 -853159574 166652265 -747832471 290225265 651967173 -618059087 988584531 -…
Output: -85114310

Example 2:

Input: 2584 695410350 557190865 555108467 213727934 -509747210 -596587689 218630306 789501510 135079128 -578798873 70520629 -743965499 833876439 619964832 43257765 419004319 968556616 -902304890 -934896515 -520406280 906751111 -578768589 -813994270 -487959568 708572988 2290333 -111552050 13651535 -261068296 473086381 571360408 672894385 -252909580 583230053 8911937 -217529894 743648947 916703715 -13444214 797035097 -496259119 58177154 658170050 525332676 -612888720 -573972201 -430531593 -946525024 663718411 -439727925 644096423 -670103944 1523041 535656013 143060421 -437166163 -651181660 33883733 -750262805 -752067497 476860033 -771550919 143578791 -463982 -971104275 -643887161 -723821372 51102927 -186325930 298664434 -439154758 930316913 812997447 866384670 -517760717 693858536 18458583 85441028…
Output: 695410311

Example 3:

Input: 1091 1043013548 818931284 -990468637 -752637324 -251854695 802386696 -423419259 -297007606 -375334638 408493248 -143740887 -531733491 -134750393 -661699476 121973106 -743778062 654995073 372584110 -462323884 991548999 436253678 430827079 574910364 -613015522 62962458 -827813288 -32895874 3070286 -625615270 27045828 653412426 375562493 -217473441 405849047 -872343670 -52622607 273545295 918064719 -295407920 994635418 274062471 492840814 680632755 -405589090 -955556492 298795446 -114222978 -937089943 -275630596 -669000027 280472697 806927569 -852690303 -822317910 -747661205 -813302910 -346156001 428704660 590997502 -923540806 -455416112 852863564 -608084950 -11855160 786473550 601945600 613784823 235091599 371686183 -524299871 -63309452 -102089962 -665010096 -563748425 771889420 -417773154 -…
Output: 1043014812

Constraints:

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

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