CT41921

The Obsidian registers of Quin

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the fen lights of Will-o-Wisp. Quin spreads the registers records across the table and picks up a sharp pencil. 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 <= 3704; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 2985 -899652 -48175 -488252 -328722 -349579 -607007 -356260 -724547 -143526 -197525 -470550 -922815 -641852 -700291 -474970 -410262 -650604 -697038 -322421 -283376 -200370 -99112 -223410 -795674 -832266 -708003 -634794 -714936 -11443 -773667 -253116 -277858 -920180 -817182 -859792 -399903 -426433 -263573 -330411 -829050 -284438 -388157 -924209 -70237 -441881 -720383 -47857 -461295 -179300 -423609 -881158 -770708 -547683 -599608 -379316 -579290 -993171 -102783 -904305 -225872 -951387 -769753 -400508 -982573 -264148 -759892 -106480 -880407 -20969 -538763 -910734 -693 -480594 -868434 -116747 -913707 -450600 -434561 -45539 -16936 -477133 -888419 -907357 -734780 -155474 -972692 -844122 -271598 -141480 -866759 -951239 -971071 -723972 -53352 -969546 -196174 -260321 -794981 -234408 -786097 -890015…
Output: -899652

Example 2:

Input: 3126 -485760 -184457 -290304 -211949 -645278 -502218 -394306 -826173 -856703 -201974 -324135 -681778 -286119 -679855 -46522 -648374 -665002 -244901 -320552 -737345 -446117 -840737 -447645 -455098 -532539 -857980 -929626 -772136 -559924 -111697 -379220 -180241 -38563 -166225 -612179 -60670 -848358 -908637 -627725 -988608 -703063 -352974 -269245 -60856 -884345 -208601 -741680 -536278 -531337 -977582 -217398 -569346 -77474 -982685 -188740 -334488 -476969 -268199 -846277 -494963 -458543 -861465 -54225 -166181 -57315 -90035 -459649 -300297 -766878 -639715 -231146 -705584 -202378 -806325 -263246 -385671 -240259 -460401 -689671 -40756 -798756 -634137 -95998 -112668 -232410 -121147 -166432 -544316 -95303 -92365 -795457 -758019 -746339 -298192 -39415 -614880 -126107 -598846 -862789 -989678 -780587 …
Output: -485760

Example 3:

Input: 1633 -632523 -305764 -904870 -393150 -487114 -424325 -384957 -33341 -47068 -682105 -646379 -983300 -39962 -665609 -199095 -225039 -967971 -995662 -35339 -525289 -435534 -727571 -698451 -130783 -395592 -208553 -9350 -507529 -565920 -126662 -459129 -878345 -361707 -673979 -149014 -324058 -300930 -615105 -271567 -890214 -203196 -166768 -460369 -289008 -580599 -426771 -556909 -856160 -212342 -948201 -223250 -344033 -236867 -47966 -756955 -38731 -631730 -669807 -223800 -255179 -473975 -625189 -172241 -67050 -411135 -1848 -400382 -96904 -46753 -320816 -2911 -592147 -875598 -63734 -540763 -841872 -688228 -615155 -565894 -396850 -938271 -223425 -766603 -484094 -440355 -177197 -542921 -724203 -289982 -94918 -342313 -17079 -674066 -304637 -421584 -832413 -569999 -164863 -328581 -622960 -281613 -8008…
Output: -632523

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Obsidian registers of Quin - MEDIUM Coding Problem | CodeTikki