CT39748

Vera and the Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the kelp forests of Tangledeep, Vera studies rows of shelves entries. One clean number will settle the guild's oldest argument. 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 <= 3561; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 368 -33268420 -747955676 -116648112 -190310819 -151494962 -343886511 -848383996 -919773554 -397509149 -145630765 -360587335 -957365794 -76935830 -434448571 -754151203 -878192067 -551004941 -643030581 -96738834 -87804532 -585238858 -61261197 -398448474 -221229516 -882495229 -134564668 -357674085 -641179316 -421326879 -576228955 -333287093 -435837471 -7321501 -342772070 -881243251 -489201741 -822558650 -184859047 -966368054 -183413665 -805092293 -981741035 -616788698 -935487252 -423944331 -415763148 -352157892 -833639679 -196537646 -304269280 -29005995 -250755197 -443810168 -563227968 -74159246 -806163519 -443338018 -234819748 -204564368 -754954323 -346787381 -622147365 -226567458 -961807058 -228789061 -272906246 -203933078 -877713283 -477992929 -750594824 -691786448 -39518855 -446374132 -60…
Output: -33395121

Example 2:

Input: 3153 -891734523 -55585837 -9979806 -407491085 -467237687 -143360709 -572889562 -816564030 -848360738 -692821522 -198398745 -424316548 -803618577 -128247643 -969964228 -924244987 -443997695 -83013382 -289753361 -130451440 -369181197 -211605651 -936943973 -316327881 -190580569 -296963527 -245901427 -643813581 -717641923 -31392662 -20969720 -123169817 -79167419 -360109656 -574697950 -640049977 -468941033 -541363530 -413944490 -220670294 -5618651 -934152971 -317168998 -991539960 -900310188 -172742383 -498750817 -506428845 -283906552 -977577438 -308269279 -88916921 -317079732 -23652671 -626252245 -673603182 -246384670 -668667653 -526792053 -429820802 -395644126 -455846840 -769837073 -599569702 -353767706 -845275213 -208338895 -390047045 -135961713 -875435311 -330201987 -644681152 -512762040 -54…
Output: -891734552

Example 3:

Input: 1813 -496802382 -684710866 -898298840 -723584640 -943005804 -95275425 -546213188 -721741306 -156323954 -197107495 -759325874 -265364529 -183120950 -550335451 -912420639 -481167548 -297450327 -827180770 -750428538 -754593082 -376091291 -140628358 -790873394 -69792190 -476379252 -106469144 -591473319 -508144243 -417578446 -68409860 -399914840 -824827928 -102262885 -254375765 -618894922 -302999449 -922632379 -301535912 -673643001 -497133416 -399686154 -698565541 -409517590 -571058566 -756227192 -295119218 -770985800 -426015400 -898746941 -872792147 -604958633 -933525138 -515673130 -934372985 -653905487 -533643497 -792050990 -519233941 -833696465 -730236847 -152461686 -695679101 -791856039 -549079856 -976823381 -723602668 -697408300 -20605803 -837178768 -745781214 -26130823 -740066494 -5787102…
Output: -496805753

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Vera and the Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki