CT51761

The ledgers at Goldmeadow

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the trading post of Goldmeadow close for winter, Tina must finish the ledgers 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 <= 1540; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 971 -295842892 -406154776 -569419788 -859169304 -320345805 -671588373 -492321483 -265843368 -589924882 -914504977 -185139010 -481520653 -830716549 -38966321 -717928035 -36494317 -473306442 -419282286 -332297568 -744869463 -117174156 -250975657 -457142047 -683795424 -248494412 -22255442 -863705110 -941018715 -604275603 -780905103 -820505201 -253670666 -105846992 -864738888 -953776734 -356537396 -744299530 -239943458 -700316430 -51706588 -476731238 -974903441 -529391017 -744698278 -948879321 -746092656 -335252403 -80196016 -348228677 -571595491 -428840117 -528465688 -874618204 -297267941 -407995754 -537864924 -36255997 -146972996 -840347108 -115725141 -391518787 -546761470 -819325782 -261137180 -124083537 -485515189 -671596279 -884168386 -495516138 -556013025 -635198743 -522848972 -701629559…
Output: -295841618

Example 2:

Input: 268 -805755196 -317561372 -599714663 -335909601 -538353796 -139541589 -208483800 -82129420 -539697793 -320175413 -684241911 -789618238 -345694631 -689491814 -424417984 -307588200 -415272697 -285962421 -863539464 -766109422 -183207796 -174875506 -693754605 -541280168 -941949508 -683835860 -992505220 -679187764 -597368794 -486623594 -358550417 -708940694 -781467060 -945846701 -194649178 -24342487 -493223684 -142454887 -700906693 -350210145 -911817540 -761155923 -364891033 -393995196 -762307763 -179115494 -849390411 -902466532 -1410973 -114482036 -652168419 -525895893 -148524449 -929599058 -253064937 -861524396 -856988072 -106748248 -282937492 -844861833 -933756590 -553545578 -60246058 -839370161 -834344984 -700728779 -220106751 -516802321 -297107584 -488158300 -78746552 -712867683 -625823573…
Output: -805719672

Example 3:

Input: 730 -196412577 -569562076 -94964887 -621950950 -601354884 -34698604 -432732961 -749058462 -237840487 -646797827 -614349528 -43485714 -838825268 -4328913 -70650607 -106775552 -831895817 -467647960 -589599995 -609604797 -610019503 -677123405 -522085804 -65464796 -594989003 -117292973 -559000439 -537732169 -477941223 -593827898 -172793754 -227053961 -910664382 -70264208 -721427577 -866924358 -925003449 -147212398 -750014071 -79769271 -482341100 -116809267 -1550632 -279983697 -895189719 -481055632 -492909598 -257901554 -770890736 -905774724 -334389072 -970723231 -170930809 -248528972 -696980839 -28587250 -432512582 -444583704 -641927747 -157963348 -910576203 -213851584 -144477720 -726494704 -913014158 -526765656 -979445360 -841349654 -233836217 -761788192 -795324334 -481058164 -497035125 -5554…
Output: -196411834

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The ledgers at Goldmeadow - MEDIUM Coding Problem | CodeTikki