CT52452

The Nearest Pair Sum at Horselord Plains

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the steppe camp of Horselord Plains, Fiora studies rows of ledgers entries. One clean number will settle the guild's oldest argument. 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 <= 2168; 0 <= a[i],k <= 1000000.

Example 1:

Input: 458 896297 609711 828444 343078 246807 516393 714492 701578 694826 439500 934084 53265 829677 201622 565958 966244 924547 908045 363264 975352 384586 581538 621346 715114 925976 735526 489629 807206 314829 606060 310428 446479 159668 903617 404109 688866 580269 811238 46214 527360 334781 78376 27295 132247 789988 487305 799398 710574 5737 181180 716549 438775 23161 598317 709585 188089 771434 420907 506889 251574 405389 821374 503811 743426 914839 449577 104709 722040 404319 502289 51962 832861 960904 56719 106074 667798 620336 316933 818252 489567 441933 911125 943065 711005 947600 621229 3040 24824 767391 334792 800423 840755 152247 913493 132228 41622 844850 946875 116568 740435 634263 527073 416743 492412 193676 41188 387654 558526 759534 38560 820933 606192 649368 6451 470470 268275 3…
Output: 896294

Example 2:

Input: 451 299521 270997 573262 977127 287155 237785 745262 386180 285547 900858 111747 441239 716630 641519 329308 795936 236429 196324 742696 492900 262918 922564 9907 573128 288319 943459 273394 471319 993900 444510 113047 31364 565497 632454 282301 705986 538340 841506 533142 795665 952674 627808 407033 71775 606185 313055 835301 254757 40723 888650 237547 436224 839503 864994 669246 337768 565785 359839 481185 849522 264894 507175 750199 194447 446206 279936 321704 532271 704360 652894 979350 309456 201302 177322 686323 789512 872795 980072 847621 576575 404062 813601 965708 358514 800602 865400 315347 519309 579589 102338 66214 906069 209209 187464 177349 972827 801414 502770 217840 76788 981281 585663 971666 703061 854842 232158 161733 284365 716673 768156 149967 638592 990268 829272 85869…
Output: 299526

Example 3:

Input: 1701 1886818 724052 161014 633204 416312 46061 702974 131037 831899 224816 510951 382603 285312 661048 162096 470038 956687 358080 591575 170022 764373 139468 408765 335366 624563 626849 972289 918431 103475 531470 52520 415405 208766 270129 457534 338055 760095 8315 67657 460869 967058 245917 396103 368784 661034 112368 44929 846735 557356 482799 259677 592432 145255 53894 816000 648289 832115 784231 664274 27192 109166 183700 257813 413818 29494 619614 862333 811187 859542 612665 853141 257402 231587 798800 577827 450855 319813 519011 44056 952502 187535 184618 36013 186778 670447 486204 343658 725050 35964 911219 976080 849037 875528 556234 89937 876308 916578 748618 242907 888273 379905 843496 140903 206383 179548 695339 484045 493566 83422 856338 247169 396093 562450 15133 976587 9815…
Output: 1886822

Constraints:

2 <= n <= 2168; 0 <= a[i],k <= 1000000.

Loading...
Test Cases:No test cases
No test cases available.
The Nearest Pair Sum at Horselord Plains - MEDIUM Coding Problem | CodeTikki