CT39200

Sable's crates Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the gull cliffs of Screech Point, Sable records each crates in a worn leather ledger. The guild wants answers, not guesses. 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 <= 3303; -1000000000 <= a[i],k <= 1000.

Example 1:

Input: 3231 -120787473 -618470683 -453244978 -515414159 -190654894 -718715367 -350536669 -520099972 -727013510 -763701784 -152840729 -899970218 -249813890 -265939410 -387395886 -307128154 -998426788 -538721877 -811143718 -73782400 -546439330 -202006291 -609234455 -784875302 -608190572 -474481162 -180806989 -688444119 -814917408 -711946856 -317990765 -374309900 -256445048 -186490355 -665342816 -922940597 -820952650 -297862602 -686678254 -745864852 -980919784 -866903673 -239503873 -34705209 -847493879 -151661711 -120649995 -758430204 -649882526 -665573736 -233344009 -87512633 -148676623 -377637681 -730884487 -559157441 -669426546 -447560544 -477129533 -958997301 -89398851 -821650598 -317309754 -55855157 -332350866 -738514018 -147908996 -549555978 -250453210 -616312915 -733130471 -603291241 -6464573…
Output: -120788407

Example 2:

Input: 1116 -20737961 -551988566 -322650503 -169874278 -234545987 -136639326 -304904187 -27873594 -472722132 -474273575 -269173951 -866030114 -265005627 -163292012 -324653093 -317795273 -862328676 -966764054 -622016363 -18782491 -849545512 -942682743 -991330116 -178867057 -101581014 -859041798 -287297833 -202478115 -470904044 -582299598 -869886073 -820154321 -201534876 -81986498 -671564582 -254537219 -658063902 -254744635 -258859185 -540836870 -70609906 -10114084 -204165080 -318333471 -141275622 -449031060 -24921884 -429861540 -49456272 -803940339 -43864773 -88468840 -443491677 -667844696 -512618292 -897239193 -920318200 -706955300 -830202190 -801665767 -889875697 -967749569 -982927406 -407301313 -425186823 -689190565 -503612771 -210673742 -974902926 -122200756 -627163688 -895753913 -131237586 -2…
Output: -20742459

Example 3:

Input: 2060 -980973072 -299875415 -321693631 -790181394 -81937493 -742044967 -982365726 -20839497 -324134801 -684017320 -445980017 -240799135 -40676511 -465112403 -589174619 -356389518 -566819657 -102070347 -58241497 -191970512 -202834873 -560217342 -222326964 -438178518 -721927709 -564353314 -46037139 -862342910 -953155595 -857346715 -321682109 -144269337 -420653563 -636672333 -215354101 -846968658 -63747209 -292404459 -499066420 -205374521 -851548184 -27063466 -882685285 -232240480 -216438246 -694564178 -650207945 -543583330 -463705152 -584673877 -937424092 -495176415 -129689033 -597194550 -302693012 -832421635 -29990704 -482813605 -429120070 -345284901 -845953356 -634157072 -275000196 -570340444 -477498076 -560013526 -441811912 -83713324 -191260385 -643732547 -406866443 -179831600 -781850980 -…
Output: -980972748

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Sable's crates Reckoning - MEDIUM Coding Problem | CodeTikki