CT41154

Petr's Whispering Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Petr inherited the customs house at the dune sea of Caravanrest along with its curious bookkeeping system for shelves. 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 <= 1581; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 103 -785242 -11768 -153115 -228236 -720104 -233300 -316801 -93159 827 -951235 -165681 -181855 -538428 -451203 -639618 -182458 -487614 -960699 -253479 -382410 -797016 -600272 -25698 -96671 -249574 -957225 -131383 -338737 -458317 -241642 -455684 -684421 -727233 -675648 -2059 -574711 -39820 -665260 -382478 -819209 -963266 -947475 -475438 -196374 -620964 -815082 -685372 -41611 -361292 -317625 -609615 -834381 -931835 -131221 -337384 -883785 -796243 -145064 -502356 -411547 -731241 -299621 -878759 -811293 -976895 -800194 -104654 -999756 -404673 -254762 -74561 -637643 -53261 -51781 -248610 -74337 -825236 -770767 -958869 -874907 -794382 -276554 -480910 -485707 -5730 -533193 -241311 -622145 -950768 -380991 -422720 -856227 -781448 -291145 -975558 -73647 -89857 -148900 -105063 -630263 -858942 -951447 …
Output: -785328

Example 2:

Input: 1518 -879695 -625449 -400322 -548126 -852371 -437889 -189782 -793843 -747220 -519955 -7974 -666231 -298660 -551502 -685696 -488246 -937531 -34551 -575622 -62335 -57093 -301388 -740382 -813735 -148322 -115993 -441071 -135594 -186474 -547618 -367485 -712013 -442762 -189696 -964622 -123923 -44433 -73267 -639635 -36489 -804076 -834381 -479732 -371717 -450495 -55833 -847528 -923211 -595064 -495235 -92582 -621062 -169419 -697787 -961585 -802823 -843480 -685523 -835172 -265586 -519919 -11253 -811848 -680204 -909376 -180925 -995431 -145340 -143900 -967695 -694084 -503849 -155699 -285177 -633508 -250127 -144542 -106837 -810331 -579837 -849746 -777831 -77247 -298559 -904431 -966565 -911706 -627736 -452680 -596588 -700845 -676317 -846827 -173854 -699840 -807563 -551463 -303255 -54659 -831649 -781685 …
Output: -879695

Example 3:

Input: 1425 -235842 -377512 -280535 -227232 -750212 -886498 -591982 -567965 -408397 -951941 -595664 -816164 -733420 -814867 -452419 -955044 -298668 -841238 -20855 -703209 -146327 -467261 -237614 -947875 -72586 -333729 -804504 -971717 -668255 -600668 -529441 -988196 -167727 -255836 -294305 -377473 -240762 -945532 -997920 -591078 -106058 -601295 -74644 -504954 -701872 -87932 -751418 -551684 -656317 -703194 -313668 -681572 -498641 -599349 -953541 -771221 -890129 -680402 -126290 -722513 -186547 -862607 -737591 -685749 -610209 -545221 -613944 -353337 -138728 -935568 -557038 -47866 -137213 -632460 -731978 -605557 -157888 -549794 -877972 -179018 -246254 -887018 -43021 -502796 -869013 -322954 -930204 -736123 -969952 -779750 -254077 -37282 -499365 -947155 -134117 -397694 -509401 -168148 -454420 -610015 -9…
Output: -235838

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.