CT45240

The Nearest Pair Sum of Mirrormere

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The reckoner Corwin has been asked to settle a dispute between crews. On the desk lies a long table of vials readings. 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 <= 2693; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1686 -432192790 -815394891 -216367709 -64109709 -549722340 -627155942 20983357 800855260 -702120509 -781905771 450393370 -691311847 -922302719 -302609201 -637530552 721234158 -717086274 -193636796 -235989888 659844685 -277620902 912668349 253729600 -854321467 981189016 878377450 969359484 -167980826 854505666 107261966 -168251069 -337081907 -277638308 -61360478 56134742 -226237836 456033775 -550084184 696570760 495938088 -393936737 230052312 -853694840 462119074 -878813083 609076057 -44938786 753171047 915968315 524879043 145347136 -656572850 -538995958 412652097 -525885048 544221362 11124229 89165796 -299794789 571643972 -616609331 -163670182 949212742 352165495 -118037389 -475272761 457437973 943357310 396159405 -722081269 599299091 48704582 -193764882 23029147 -132536219 -446400923 -912…
Output: -432193936

Example 2:

Input: 2463 1529361736 -295422960 -367716366 -12736752 -575548900 646357745 -733213099 131743744 -565666819 271359234 -505044579 147138265 -208492106 335970403 748788262 297410171 -905583448 -522141971 447884992 483032101 810674923 649782614 918886893 -428228436 -872676832 431499351 156747294 -247037116 -764124112 455140641 37389624 522718833 34262942 -503106571 587232045 152507434 -797339346 56343602 149434482 -111006225 -301597823 299861597 -130174690 -670213089 -397108298 920516089 351067478 -775553835 -230353255 330288743 -798002413 -983852511 -412273488 -735668032 -240894052 187199177 544864946 -331944781 -116926066 82817039 865867618 526792599 -753296853 -754857706 -217657648 -79463589 656821230 67896668 494928990 837112261 537618759 -640186907 872483420 -868751194 -549778949 989066819 -743…
Output: 1529362435

Example 3:

Input: 975 1772032549 472605797 609321991 267103802 428697582 -615201313 18403090 558409108 -784472328 -436017515 732402341 -898811188 243747384 153193706 -200724856 816636285 -841376669 -133467709 -403826042 -900982028 459026508 -231630011 431749159 486732117 782851715 -135324719 -681191156 -668402117 750723814 -793202101 -304954119 454340114 -350172275 -280428942 -416745002 536703700 -301412245 -618791685 229556808 -404162237 532630023 -122873527 -869813083 49932716 -377421076 -398866460 104264454 438147857 -185323505 -427681037 351463995 -766227525 426406090 -615479332 -934788225 -480719673 -507190108 -681713576 -681318108 238659312 -257144524 410829070 -583251943 214551369 711226896 38161347 756386023 110301915 -778753721 -444901242 -900968339 30689268 573394153 890868681 217637554 999836693 …
Output: 1772004011

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Nearest Pair Sum of Mirrormere - MEDIUM Coding Problem | CodeTikki