CT52652

Last crates of Zia

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the caldera rim of Firewatch opens only for a perfect tally of crates. Zia means to find out. 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 <= 1520; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 248 -650643805 -864356586 -366765880 -958470499 -794025857 -625351588 -821810560 -109103652 -989273114 -584080091 -284380301 -11166337 -437574187 -220102210 -653011864 -806512610 -634652008 -187248748 -722431370 -576604287 -36232221 -235247599 -981396325 -122191246 -647404252 -716142350 -334056722 -928704495 -174851782 -139467431 -360763782 -787398405 -670345883 -911220177 -664899130 -709653842 -683176192 -304845787 -735971751 -184110969 -840777772 -624018705 -624210260 -196738214 -147441952 -408369191 -643560714 -313807506 -4333489 -215894222 -435220490 -229360600 -56823300 -817253859 -938013124 -552742679 -368979557 -278992814 -211149179 -672803248 -18085802 -124630317 -55087126 -651476418 -949114507 -383147755 -843181110 -521269660 -617230488 -229104887 -915832841 -255852364 -517209967 …
Output: -650655302

Example 2:

Input: 1464 -634192623 -444230843 -135967175 -754524062 -888047163 -900731031 -213483446 -314557829 -707517478 -376873498 -173001649 -678791507 -237235427 -261271521 -262872050 -787048400 -769577915 -359360563 -73278128 -368780229 -77167460 -298331085 -510061752 -522092066 -836201852 -894800313 -112060310 -310318 -262710322 -269768960 -908504539 -160570403 -305365279 -653708146 -832229614 -700555907 -638930335 -131956713 -127584607 -653024458 -580303408 -703235184 -532592834 -979542037 -401113803 -488131011 -162303207 -862877643 -987812624 -468155529 -457238613 -299199782 -244893502 -196838958 -460701477 -762971129 -875163511 -475658272 -689817131 -243556157 -911646092 -892898399 -130946208 -941902944 -720696270 -682796664 -629622591 -591225225 -583175907 -884066365 -773386829 -800658783 -8459181…
Output: -634191927

Example 3:

Input: 9 -631549314 -890678298 -285297466 -779345663 -901725854 -367026207 -505030145 -925596994 -674492934 -375151415
Output: -652323673

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last crates of Zia - MEDIUM Coding Problem | CodeTikki