CT42802

The Nearest Pair Sum of the Coral ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the honeycomb cliffs of Beeswick close for winter, Notary must finish the ledgers ledger - one figure at a time. 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 <= 1241; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 400 -182986670 -889234852 -252986728 -122535390 -820055598 -210881326 -101974008 -417142781 -888163138 -622685636 -115696126 -895568596 -531557608 -819148461 -33797272 -253815748 -814214813 -286041399 -551025869 -244249981 -267427890 -268934771 -378214806 -992848653 -241648202 -186179221 -905380535 -904632704 -311142277 -663501972 -883423923 -779939276 -801380580 -280206728 -34272852 -913790820 -787525378 -393972107 -981949968 -798115124 -893048801 -571402063 -562723550 -251931005 -954956991 -653672765 -680367206 -573866866 -530633126 -948409477 -415820646 -619646483 -781354315 -174208160 -264652179 -142949860 -751555788 -262880725 -136723355 -52144001 -929624016 -363421393 -562573057 -410583638 -481530068 -889261354 -936954224 -210757326 -193492178 -864128684 -565360083 -88122887 -9362472…
Output: -183015581

Example 2:

Input: 478 -449603311 -886612759 -765414038 -213507537 -705460532 -589917705 -489975966 -116054854 -906807119 -329583945 -511465461 -773953027 -770101025 -784712091 -6982662 -310895345 -633486127 -38333513 -45905717 -130708115 -912750256 -584412764 -768927106 -683589486 -269010043 -938470709 -709122555 -231971406 -285214650 -739859589 -326727791 -474282023 -240573679 -233385800 -707957255 -677650563 -495152298 -941071756 -870794493 -343403896 -671840763 -396651525 -881532130 -360992633 -609907217 -439180105 -562220191 -488008987 -981895737 -32906253 -449747834 -850661016 -162454640 -780402088 -471525287 -207076902 -542080768 -781830538 -656462182 -602990224 -182811881 -37343525 -195569250 -197102489 -478889274 -308295948 -148882317 -256891839 -839764951 -396773581 -906516536 -576854239 -167626770…
Output: -449593682

Example 3:

Input: 936 -577339815 -22924310 -785894156 -183651490 -400224082 -853101926 -383884232 -205231111 18935 -488851093 -728480997 -68009333 -226430495 -691778771 -38360370 -822519025 -973127975 -90124314 -72000353 -603848939 -607569617 -820691905 -121123458 -303684734 -144021704 -436727798 -959014449 -115337649 -896605830 -615253781 -215250062 -846832757 -721150256 -348920979 -138003017 -655994651 -624049116 -869827711 -163223100 -752719783 -443627173 -73724554 -756162939 -258222703 -605481801 -39430026 -214262742 -545868065 -469483260 -868300160 -498046978 -237850929 -490830985 -715887075 -591895038 -702788991 -842208609 -6841976 -988622743 -28567237 -154412632 -218834673 -939748508 -990598710 -996698359 -54025715 -965426683 -984480061 -140019170 -392542618 -527619305 -104126502 -227606584 -42638069…
Output: -577334252

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Nearest Pair Sum of the Coral ledgers - MEDIUM Coding Problem | CodeTikki