CT44794

Vigo's Ledger of shelves

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Vigo found an old ledger of shelves in the shed attic at the port of Emberfall. The margin notes pose a precise question. 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 <= 1554; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 315 1931376068 -653172910 553126551 660769123 -578641833 919254664 -107602887 221807963 -218745666 -628133994 -651876388 -33995922 550275128 590205642 219727355 405310141 402048975 -898551354 -707280983 752262871 599407175 191556587 756980850 295924006 -149641377 363642703 947584125 -364180219 -586848153 764966788 398665804 -153995900 95057397 -259348579 -600155643 -761963099 924661623 526272097 226934944 -310343076 -737646556 730978676 -538051483 -214658999 -917082013 953631833 49329515 -702115571 -348880836 -940344431 635133447 797967481 336961574 -955297170 85391414 667725628 133008137 633678985 -462625477 -563995603 551535628 604730074 900815278 -726664601 -387696600 476042846 760249682 -868655867 774082042 -546424087 711487793 -898509374 715645929 -83099903 882310081 -205479638 -55458…
Output: 1930091489

Example 2:

Input: 737 -886796025 672556062 338388369 -346838002 539802471 84657992 754299037 464848636 -658700940 -470104808 -534825562 -109023985 -670810667 -555493844 119059390 -762495146 953197099 410388783 344067427 -51213870 -260772307 -583342197 -397284690 495675837 865990366 11394882 -198249147 -678479270 -628873574 -594318118 461993893 769187545 209572959 737569009 -923935420 142159129 -181385187 798802626 735211351 608045766 708240540 134392391 444015201 87649907 -187692180 -363133884 -477537195 664642886 -575165434 -649159354 141193006 851483941 684132699 634668447 -586337877 -739125514 -872629314 89027636 4024677 818402600 261959227 -604807152 -290245389 925769549 -17812320 506213003 973362235 -847711754 -154913152 111360164 -754386065 571280096 333608620 844512514 -831742760 184253349 -352049619…
Output: -886792788

Example 3:

Input: 373 -999190524 -90353012 800688738 927234288 -858289499 279003673 320023331 999182884 -913720995 951697357 -426259502 -845323319 -328863421 -374936024 346331135 -690470178 -836568444 -516156167 686680380 -323718865 211064651 59984877 -473913441 -860544930 199152396 -551328776 767473770 743441668 282740226 -839535931 146753224 -498262110 -107333324 -139546688 -672777941 -90909631 772883373 603858043 -627107268 733925949 -734963925 -188687088 -631485455 -663686802 570728473 605493967 999345545 668912687 368633116 862000126 -576113490 140076068 845094618 940003214 -53175925 784055430 111395947 -201117797 -934278624 38959599 667557623 819719693 306701947 548272022 -661193631 -31623 48175364 583753690 321817276 407374021 -10068999 155516532 -472046816 581131961 -249277440 -299408507 232569854 4…
Output: -999175216

Constraints:

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

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