CT35035

Herald's Ledger of weights

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Herald the registry keeper watches over the ivory gates of Alabast's stores of weights. A careful computation stands between order and chaos. 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 <= 3537; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 319 123340266 330578744 273610781 687166029 -494004820 445072244 394638568 946790507 880186380 787566203 355473761 -2332614 622347458 -759065541 560153552 943038323 897684511 319840544 -406124673 495243789 650331865 352084829 -248081521 230036794 -968758698 -787305297 484471684 629222158 162412310 -137989162 949001452 688946034 243547762 -696286640 -758206122 456397530 134484915 -278744579 -128180963 419984612 765167655 -600881910 -533930506 -930061439 823048390 -748919449 687170866 -193224572 -655135608 -397808854 372608094 -996797500 11836362 -825814507 -4471670 -51332478 -425426834 833453067 640249724 750913696 -271920939 -636324406 770060847 -837357596 -481133106 756587753 45086519 -815987723 -933541686 589381366 -680790011 -805703249 909632865 -452091958 -797230911 824851453 -67665531…
Output: 123359086

Example 2:

Input: 2027 817433330 821716127 20909487 671415388 -422645005 -84913071 90417935 834556945 -40018163 -542965364 -864822837 721344504 171874137 -738780450 754054051 -502440513 418879051 -663934286 556445258 571122537 -491865580 -788897900 -443799307 311753959 891024552 572223186 -130701917 -67878354 -772562794 -296602168 767123741 -221461263 839354120 -269181026 446523060 434926238 -629392624 63440252 -649519374 892470180 -984607110 739883243 -420272076 -937188563 44598859 883872520 966029222 -702823651 285218445 -977651567 -854862795 -109400010 412374445 121692924 -967686234 5265766 257768281 39492764 463893960 -444594170 -953212147 426885753 -455609522 789497216 679218312 170332136 630096483 -577222647 -591433542 -288790078 806023093 916146572 339474555 -229100885 288236578 -790410748 -725001532…
Output: 817433470

Example 3:

Input: 3362 1818205907 608615996 322698618 483360235 596657210 805418498 58801376 68866476 -45162227 554143132 535535516 685305067 636069747 -290885011 -133457760 -672160833 136575077 639542027 -356675347 84917592 -149580856 998131046 -839534785 428574278 -315973985 89033667 -435865974 436030615 -516975042 282643497 -708257676 -387276816 -980862430 -483623708 -312839303 -880231829 855187686 -903010904 577766726 585058178 -261360789 -131936994 610030899 836842078 -939941299 -49304695 -179845586 -17547222 828162759 -450253887 816537644 -885543019 776140743 -40247673 -729228359 -355830082 -635805754 -862380872 -143500107 -912420069 500637247 -334462207 -325849129 540244404 -938962043 52433378 210620025 -106080925 128431760 236204138 594098361 857763622 424748698 383363791 -164040306 -570980130 86410…
Output: 1818204909

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Herald's Ledger of weights - MEDIUM Coding Problem | CodeTikki