CT45230

The Polished shelves of Diya

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The council of the granite steps of Stonehallow pays by the answer, and Diya intends to earn it. First: the full register of shelves. 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 <= 1890; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1855 -88261721 427873778 463067894 445673524 -961159866 -344010623 537141888 -727819652 726368060 314911883 -646197716 774488209 917847135 -753364218 -888244273 223769519 -493011877 -384133616 -930435149 559368768 -671556431 -417724754 326785915 -735852109 13510154 -163267173 458754697 -65851048 -751069177 434070244 59533571 413147723 628577635 -662534924 390622376 356278384 -160407953 217768945 327587676 425743194 -455716699 733032681 -21802372 5930501 -665479136 -421221214 -902385758 30797987 338598798 589727468 857537443 -440169207 240064116 368431744 -335401917 797138199 123854300 -15154957 810111440 -800439339 -67303908 -561719825 -860017281 251359406 -725103153 -392302330 809100724 725111798 -185984521 -743934468 849177743 -251988017 -800020989 -909114933 218300460 582592449 65788438…
Output: -88262971

Example 2:

Input: 1503 1376609238 360089008 941453422 537097063 887033508 752814264 74216713 139204028 517179930 133615284 -469359046 959939730 558229978 563014512 -266999853 347363865 77569511 133599734 -755001227 209209946 718129141 -196409663 820625359 -708143547 -11500419 701718093 434455583 -943771647 -285922241 978403352 -496168860 544325680 244112088 345370702 858725883 554522794 613109533 -688412910 18163323 -447989992 -835736020 396234790 597343212 -49461674 424311840 514687104 482508017 167666287 -287589242 816310442 -248777601 -39540639 -74491301 -372738531 683334762 645784579 -344335229 -156347175 708871992 695382098 -916677061 310098222 -558680589 -702043101 528888184 -716914030 896152735 738705132 204023774 -828908138 -860935902 -305607515 789270798 777898675 847662906 235729494 343485415 3599…
Output: 1376607796

Example 3:

Input: 615 826381854 572096520 788905094 -692128018 327579448 -961020586 -528309179 -543981892 528359201 -75299023 -798763778 -785694333 771817420 620015368 -581733722 873069835 -230240602 674025866 758358274 122500769 613077493 749994424 -861902123 -692957594 506479256 370143709 -552658160 160257101 -641829983 591769075 690468760 -959024399 345589902 -713588334 321272187 -877197337 200792987 846739484 -717533946 465754769 -11264350 -331914391 -116642176 961897093 752727528 841436431 58563530 -12189414 -542754137 403990876 578411757 713932228 -729501376 171380828 -229366379 117485052 385304929 371125534 156363849 -320099859 -77025000 599087870 468183326 -611107746 556716188 -202967858 -976893862 963637069 -572126700 -278693262 -502155585 81177688 -719417907 -944294924 -130568514 769620799 3692176…
Output: 826389250

Constraints:

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

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