CT39722

Chandler Counts the registers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the terraced vines of Grapehollow; Chandler weighs the day's registers manifests and starts the calculations. 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 <= 2897; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1854 53917434 471464034 430052230 909999583 320354935 130426582 454108001 539449257 492684107 102777983 233860946 621796651 552266029 294665587 266403117 374044562 423113216 535559838 280819661 54239847 845337849 132618686 15339064 85319485 5691065 438717905 18945712 777795309 881063327 361136544 102759890 241610622 928281832 837027764 211574965 757762061 975178047 503756469 499011037 946452685 453067366 897706356 716667767 686324820 881678493 332159991 703099295 10677306 64040967 288666431 137544743 657818463 92425006 915742331 749845170 796486567 443130472 643773281 409158033 927802376 19331947 339823388 839964813 394298072 532704413 172248321 807373007 223931732 225177453 233994548 435810594 579082616 330340476 529591717 441562171 847291927 331553004 215429814 389451161 909915737 551590…
Output: 53916569

Example 2:

Input: 848 663781396 523632341 348284308 453678413 368612311 449474187 788565315 350995919 834599329 249169768 564685638 694823887 967110778 81029819 782979989 583112114 278297457 694912793 569186728 927756231 298106650 731643065 -643716 196961554 550123695 441228508 697972097 381531967 316796333 100223767 652401251 600443084 452649160 138464599 322358970 724870009 811073079 60194877 78168005 250003727 145933281 612033614 340637124 939245632 454723609 992348547 348149146 564329807 571301077 325688410 978242141 439639627 778439251 860914760 466830763 333791482 960522678 382095493 282564769 646332139 14319282 997649625 323293922 296160942 144578131 6199785 303270004 566371367 147361140 690169827 264055285 692880960 330965317 172820011 524651632 533995691 755780639 534970268 912804979 174533144 7867…
Output: 663780722

Example 3:

Input: 1340 1538241584 83782693 260175511 835181642 695257719 991462114 431297156 635048584 425396025 574677250 53518166 364055526 440717066 586389091 895532920 318717006 733731476 55249938 977734272 261479767 123995193 310640275 894473086 593826510 158589033 57745142 437731513 923490671 265840453 398319010 322166118 438445742 999050746 550231462 592580734 649878179 962453752 495891578 932586867 904930232 478398703 776554925 3267255 71276202 192149762 58234740 42869765 946777701 809964807 11480439 942058574 588027896 169720597 235041629 562634149 877841416 158917123 733935668 413306205 90556042 916560628 213589206 204599124 681055376 356210513 497811763 684255777 857715929 711707794 616257882 10437928 789293378 450261157 521179720 695610838 834525996 298327676 516004353 82360652 297046324 4495709…
Output: 1538240404

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Chandler Counts the registers - MEDIUM Coding Problem | CodeTikki