CT55383

Leon's Nearest Pair Sum Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Leon inherited the loft at the river town of Willowford along with its curious bookkeeping system for ledgers. Time to make sense of it. 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 <= 1534; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 508 -277323518 -75125511 -147908690 -479464318 -996957504 -316892825 -34331059 -424929856 -55609451 -953739161 -651157335 -611680479 -799045347 -702140607 -608601962 -104068651 -192110797 -371001428 -530295026 -11222755 -38175381 -356369928 -670003835 -399033179 -512657846 -632849861 -614234090 -676873811 -471174623 -95729337 -823839906 -486896399 -339294010 -55594431 -740733440 -44313263 -948461964 -159706148 -904217305 -809375029 -68419247 -328834039 -102335581 -834874691 -768096091 -640180486 -433224275 -968468582 -783245804 -13968664 -966395501 -236578617 -793405771 -749500207 -689323925 -398330521 -603575110 -561325469 -691144204 -894789118 -80875710 -59314086 -370326613 -797452570 -477013734 -26081039 -754976717 -923508989 -778341366 -968841100 -644631621 -277998041 -119593626 -46359…
Output: -277325330

Example 2:

Input: 37 -951557186 -837129351 -665268135 -912355621 -215005800 -989886861 -988957920 -19011819 -258814372 -710076449 -505087180 -427513609 -935459250 -399816701 -355779767 -736346772 -208265429 -441300758 -713989604 -109180146 -224686345 -923591089 -356379512 -352723751 -85385951 -289653370 -861748722 -644957025 -49581551 -310014139 -10885347 -872703097 -680973659 -337710354 -817084947 -713135959 -171749456 -810900467
Output: -951352572

Example 3:

Input: 1239 -627819599 -536306535 -986614727 -254472971 -17769828 -626014979 -335362886 -874112488 -222340505 -566848681 -34629869 -66239594 -936257991 -992429311 -701320830 -281006955 -997680733 -832113137 -410183032 -244471556 -730487031 -552291132 -960352265 -789412348 -289368021 -427846512 -469307171 -773253112 -468281587 -514018507 -561918234 -699925069 -227796193 -865528164 -55466168 -576173282 -314728171 -332158491 -378711664 -531768302 -108691397 -643527588 -154486443 -212231424 -13666325 -799935259 -993152184 -110053962 -272439800 -839187493 -738059327 -599696523 -699644150 -426470590 -419009135 -336303405 -696378597 -429565985 -531423684 -131246688 -819801899 -529457533 -170575721 -431679859 -33319686 -278256900 -821458027 -972383605 -570614428 -701933759 -795637988 -163734189 -75538821…
Output: -627817490

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Leon's Nearest Pair Sum Ledger - MEDIUM Coding Problem | CodeTikki