CT52014

Lara Counts the vials

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the foggy moor of Greyfen, someone must map a faster supply route. This year the task falls to Lara, armed only with the vials 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 <= 3803; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 2859 -518768063 -881081278 -457121152 -766692251 -271394336 -294150975 -150919016 -56717733 -480027402 -667685676 -155749249 -210684149 -207044891 -240887602 -680525301 -793095392 -416937435 -804488567 -493052664 -209249150 -211372416 -73020701 -720515167 -277650628 -99115962 -929710630 -388843253 -776304348 -131652825 -307373073 -652355291 -528524476 -203189780 -199733446 -631274177 -256023780 -926216477 -48119570 -383311649 -175493501 -641325227 -981964339 -758736608 -12136162 -944749936 -533213950 -719628180 -809521633 -149156989 -707743814 -711542948 -943606368 -980298095 -103211892 -854692506 -527189917 -937092184 -841735822 -650225819 -68871977 -620500333 -916746577 -966257954 -334161501 -39383186 -362883865 -337738152 -897336296 -58529575 -216365956 -833022060 -982938513 -330781960 …
Output: -518768109

Example 2:

Input: 3131 -956463123 -603067214 -786191395 -470224739 -906486133 -836600394 -808093939 -823080585 -67193826 -51708094 -707747107 -259708662 -414489031 -342204978 -272034858 -333648008 -93228245 -711179833 -52227712 -984168211 -268012463 -448788136 -582412285 -287168787 -397946931 -487008828 -194749848 -592134136 -577945162 -306323592 -446658332 -951313604 -535174644 -611057931 -915843800 -47050573 -228938192 -821298379 -961529883 -343161067 -526877091 -852993274 -681351774 -198748690 -125418573 -931381093 -3147583 -468070658 -790285749 -555768917 -418800661 -860872697 -289773492 -547911373 -808856704 -110206076 -435447410 -457814662 -191258001 -506261006 -733986307 -697004495 -196856307 -830487863 -944476351 -454847918 -988133151 -60812847 -423535228 -634338022 -848516892 -339072357 -558899448 …
Output: -956463248

Example 3:

Input: 590 -913726314 -960907238 -163890778 -470918500 -748120915 -163969010 -510722708 -118941561 -985663722 -935165093 -872438724 -468425178 -525903256 -464910473 -23620500 -845769803 -810115712 -852338531 -517650921 -931031952 -369703138 -236207429 -93086770 -571575852 -47400683 -718514789 -56153501 -963131226 -19035270 -964092210 -442336087 -311234878 -775334843 -408126088 -505280803 -144972858 -774875889 -384175062 -77629690 -198143662 -548438909 -146637411 -99527086 -818230089 -61867276 -709444005 -874048006 -903046505 -774873484 -537949726 -22210926 -843554814 -797403972 -363506331 -428553520 -927846123 -969408309 -233573735 -670684979 -448776445 -638276918 -343472059 -295403294 -667491584 -806228460 -613783258 -700799633 -779717427 -67989541 -311128468 -149517782 -692938753 -747964442 -78…
Output: -913730393

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Lara Counts the vials - MEDIUM Coding Problem | CodeTikki