CT52759

The Nearest Pair Sum at Sunspire

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the temple city of Sunspire; Urmila weighs the day's ledgers 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 <= 3928; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1812 -851591096 683795551 900454160 37462184 -454366421 -962884404 14054599 728311477 992571678 -71863740 380888773 79470641 -899058863 -981593171 -82261591 616458434 149603312 -577476466 -809511677 -394812293 923932523 151517549 -740192373 50447106 -330926262 397424580 -950012492 64980369 -447676074 -24152524 948524502 298164646 -123804576 221054270 -792769724 423696252 812084460 -857430238 -563592077 -517871181 -435904481 597542932 -403547564 -140993983 353268766 -784814209 -279150399 -472948181 -425843572 472634138 -898737425 -788369730 -713748099 -412601929 -162990579 -911856339 127895874 -642451313 -111982164 -452336556 -113521026 -33176878 377997759 -234983982 -993716928 49844360 -845800075 731186273 -372057754 703057584 -858916659 -817022030 758749481 556365424 -253973074 -799752704…
Output: -851594076

Example 2:

Input: 1035 53479431 -297785110 503606237 944250322 100585981 50406703 -880355504 117283889 -22823030 731047266 445360579 -521806347 709192569 270940799 -275414180 636039111 842484080 490534043 251270445 -61803607 821769964 -167479565 -630850575 566354534 -986946986 284868525 -496167198 -506067397 213127880 47254022 -462630053 291837937 966010836 911879968 -673045434 -526800812 374211671 -743925976 931074398 -459989381 634437160 -658823675 314017083 690152615 -828124300 489172896 -146028260 -879709745 -977505794 -304794983 -408532899 596167796 -410238450 686953469 -720982016 -270769273 290300680 -351663882 304029946 -363735876 -648863336 397542790 -587216707 143539139 843623138 -780453261 -757978442 477554716 -260434365 -481808618 -608663537 114057397 528098017 2499405 595499122 -616617700 -93865…
Output: 53479692

Example 3:

Input: 1023 -683796434 126009411 -953386715 989797491 200226938 578545923 -70877147 -926379796 -740979314 -494531607 -385810293 -573281393 960037068 -485814845 -256602076 -696827121 940298599 -155719816 861142380 -749767840 -180351658 116332268 -667742199 -554895910 -134333896 -620474123 -399658873 660000232 284275577 -486640128 -527884004 -491260900 777885052 51129935 -179556327 -859610904 164079858 -731719546 490111406 193924132 629483913 155908360 334360762 246641857 -319536561 -465908981 -401271884 -689925881 883655888 159526281 -618789785 -971511512 673868819 636757023 -285782684 190606242 895221451 266305229 389759712 -520563488 577584039 979347242 -259465065 -283924216 -711233688 849321122 -734531585 358103617 -798248747 -554865497 214228397 -46453804 -691277140 -535509435 548870026 619526…
Output: -683796544

Constraints:

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

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