CT39900

The Nearest Pair Sum at Gearford

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the clockwork quarter of Gearford, someone must inspect the delivered goods. This year the task falls to Rowena, armed only with the registers register. 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 <= 2724; 0 <= a[i],k <= 1000000.

Example 1:

Input: 2713 1358782 304738 158573 910711 749691 790815 513566 50568 369645 11750 444106 416299 510922 754435 469234 302089 73515 993449 755526 605478 69617 12550 957969 11086 359075 11536 613248 109114 189871 969897 878682 857738 545532 636437 637097 205896 437177 84933 257449 746103 534786 809981 893703 258114 772268 43226 601144 388984 688058 226910 929214 298520 433236 55607 501665 966479 384193 764009 265305 416644 435454 274713 425892 162015 167407 917757 882300 860758 749803 224281 745742 171948 819599 324492 504754 95907 172797 969670 11054 458749 468117 353729 452035 460252 273339 323670 170701 654904 374934 287139 605050 402112 889581 771274 836263 441327 146571 280292 215060 60649 370979 25153 896739 666001 135179 595584 793202 396231 798650 112754 997523 704731 395549 137735 31223 9074…
Output: 1358782

Example 2:

Input: 1416 1646514 437430 647476 652416 672832 429394 178302 669860 329638 861119 312609 551231 693243 380920 771109 346918 254116 115797 457706 982114 451532 411672 317818 407838 98347 191626 64781 283765 117401 367510 479049 414547 558486 437773 39203 990415 947266 520958 65750 394154 600319 52669 205812 121580 951439 270538 269175 340648 82780 284854 557510 989796 701070 850544 351771 635069 129029 146054 334111 25603 74373 993384 679695 437928 832986 76857 11846 743022 532758 380832 655504 99448 940678 408740 532158 317594 684143 664265 472405 652121 495900 390458 762393 664377 846800 514007 930868 978662 674694 901389 334173 568904 275627 123922 919987 697732 705208 886353 882302 320556 850946 69158 464348 742813 598957 976901 997435 37629 352905 58025 181720 386597 943538 649942 791189 461…
Output: 1646514

Example 3:

Input: 526 1614272 853685 711049 233707 482498 995869 175125 14576 790343 519864 861113 592897 529406 531311 953965 589744 921298 959248 316090 974552 547541 709986 427260 199934 924276 176964 273815 55129 970342 776620 41285 752479 662557 112633 957688 517863 528643 417045 498520 160267 669174 877057 804136 264935 614180 590745 978318 737098 169131 749678 193646 151103 342418 574840 355520 495462 154964 258400 342983 537933 27281 810175 814079 305127 123241 293750 316479 841475 22508 528695 233920 124606 368699 959266 583443 380124 446657 417360 959640 811694 809800 802847 715740 352416 900771 669188 673251 23452 423796 580971 44489 998614 803966 62890 37952 751032 855114 785241 427628 469178 360695 139166 466884 247745 223735 430142 733922 897807 342604 17101 417051 964049 865115 827328 592745 …
Output: 1614257

Constraints:

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

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