CT45263

Aria's Nearest Pair Sum Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the poppy fields of Scarlet Plain close for winter, Aria must finish the crates ledger - one figure at a time. 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 <= 2987; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 2714 1807295915 -97375421 697901074 932820542 -662623253 -823446019 309061353 -979214838 -310348560 236564983 847254169 -144865787 -745337634 895045580 459577763 109247284 382342152 858374428 -62131111 44635649 351752327 851984465 -607785264 -845011692 -983880396 -483321561 -834032093 152510465 607473298 -656297777 -664483611 -844456909 -292654339 80639023 -605504666 887130416 857146894 -24488359 -192501815 298160157 -697070223 219101658 -578629579 779284022 393555983 -819418164 836606123 129799212 453610845 253447319 488823926 462760351 -477972714 -63037383 413856140 -855547332 -544206236 -50455182 692504442 -897135181 -768309043 72303768 -469448284 75100815 -225162887 629864716 542656863 460090225 705315877 692667605 -964287821 -154554583 965436002 -599604082 150128664 692801270 63450213…
Output: 1807292659

Example 2:

Input: 1046 1526319398 -318012724 -562842448 -724143172 883116725 -507758805 544244861 -415631796 -405861817 860673319 215407649 3782524 937566003 -396394984 -738545194 187625144 958753097 -512665190 -816776913 -926095459 -372358958 772170041 -846475999 331413972 206978112 -429300967 765452587 -862209117 726931293 146556199 39354100 -2198437 769598733 -398977078 516325196 -716595122 712169157 4030986 404670774 -543362653 124435512 573210175 260456948 -439589130 105366650 120188777 -91855971 879266423 406152596 -831472559 381225327 538501041 475976434 -667245462 -828428846 -945916389 382300155 669618217 -875468865 -817327414 -861401075 -963466654 -169734710 -662463886 -788679486 138685046 760707581 -928115271 99928452 199699759 719118562 265010531 413389192 -622224272 -242577721 -118939611 -493905…
Output: 1526334101

Example 3:

Input: 2200 -578107385 495045165 627673605 68612663 -155460309 937744772 -865346350 400318134 -608830760 -260698832 543840040 866889058 284825911 -886740256 -604510533 -472445003 877803109 952381391 -970030964 761999720 589495929 -772256944 256442632 410015376 -701022811 218916245 372710922 -667070784 92813494 -838255380 -900323463 633489508 44624492 578654991 216871412 -494455282 -478507746 -9314978 828797944 -509692346 715891383 659667517 -27238369 -751287785 9798331 958117733 170415563 -979827760 -47202119 459798825 53851338 -710407860 176256997 650513949 734375837 -738928916 -314342580 -566231475 654791970 -902711693 -8512062 -848774001 -144137318 -2326669 -724982994 -610351268 983959936 -559952642 146164183 265777776 91184981 -240003769 984793217 -55671037 193233701 314296564 448766967 50370…
Output: -578106902

Constraints:

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

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