CT43305

The Ancient Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the obsidian flows of Blackglass; Wren weighs the day's shelves manifests and starts the calculations. 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 <= 1293; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 1244 -241579 -437253 -807620 -969545 -579787 -972261 -138378 -177473 -441883 -92440 -28547 -809419 -814646 -477538 -619462 -587641 -994208 -874708 -708900 -433227 -594816 -249757 -693910 -774815 -27766 -762029 -444290 -80236 -73110 -940588 -615535 -165394 -129360 -903172 -169001 -217160 -76936 -544234 -894633 -478417 -27109 -688011 -278813 -577069 -45348 -949118 -106187 -653038 -134031 -734576 -165264 -195319 -692888 -182239 -80488 -434498 -240150 -158930 -679045 -406735 -971673 -492608 -647780 -157276 -349144 -693386 -77445 -40631 -897814 -716789 -431459 -766853 -556141 -89418 -149754 -103450 -372661 -932401 -650848 -400110 -590330 -940922 -387815 -630156 -299509 -696652 -543713 -853992 -460728 -890789 -622959 -40122 -555321 -734989 -87366 -900829 -583998 -422046 -80273 -344388 -758132 -2…
Output: -241582

Example 2:

Input: 219 -45734 -357305 -175234 -780316 -891329 -435468 -245545 -633958 -594676 -204089 -749335 -707524 -674797 -193654 -545212 -519698 -566556 -900038 -10219 -818426 -341882 -303835 -71843 -308057 -98076 -504101 -705510 -721447 -13164 -388587 -727214 -190146 -112338 -502028 -680248 -696590 -730123 -758958 -365549 -959811 -627739 -43018 -489745 -562841 -929714 -341960 -676672 -882928 -441730 -102060 -365363 -838225 -942503 -808792 -512519 -538679 -981270 -630603 -545276 -343117 -928898 -338932 -146043 -998534 -79369 -167621 -634438 -384529 -86257 -925260 -567853 -982013 -558544 -490275 -711183 -58775 -983565 -96541 -666303 -498635 -119806 -633782 -228301 -755576 -630789 -205866 -318171 -798756 -607848 -749845 -526836 -623876 -527894 -283707 -964765 -920222 -612838 -388362 -378902 -697111 -59207…
Output: -44461

Example 3:

Input: 598 -643133 -958204 -72059 -103086 -786050 -764770 -451090 -997078 -473093 -194876 -543820 -711474 -174408 -982831 -174748 -974236 -538727 -789572 -907180 -290472 -572374 -269478 -125593 -98407 -669438 -599558 -619872 -196013 -487062 -401319 -162581 -20723 -536576 -867742 -122393 -14848 -132324 -42681 -419758 -904496 -845217 -491418 -775281 -910048 -919785 -975155 -600254 -748841 -557270 -528126 -934501 -111525 -322636 -479988 -762133 -735402 -386878 -420032 -308190 -482471 -841230 -82099 -960155 -606613 -13160 -236014 -29002 -261512 -562666 -513959 -540204 -23846 -327593 -805063 -566294 -567766 -154617 -820892 -267129 -622269 -949738 -546020 -860846 -519288 -239962 -733700 -425901 -185694 -415217 -495338 -551692 -615827 -537996 -653563 -480535 -208212 -981536 -706575 -876388 -703266 -8692…
Output: -643121

Constraints:

2 <= n <= 1293; -1000000 <= a[i],k <= 1000.

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