CT56047

Iker's Nearest Pair Sum Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the lakeside town of Mirrormere, Iker studies rows of shelves 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 <= 3573; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 2763 280519223 239481598 477191315 925626630 560094423 988064013 945677728 301886660 710800141 612898610 640351103 719454024 52913526 664837054 395002713 323811536 816393354 288842777 103722281 416404280 668828750 361274340 165409696 127082083 266031082 551490852 850780592 23128607 882602223 97433069 795119019 818637805 1028521 898456131 646361663 724897071 868757035 699922092 503171068 470424103 272865189 980397788 948039055 535137228 265025786 994024374 272932946 702524297 436192863 854914434 133222882 380855260 661911328 681770780 701477474 435336982 413989150 399345199 190706431 400340754 806450286 328449847 571568353 92163222 932888223 112907570 271713739 336158209 611580370 377368136 585527333 471465134 344708328 201005747 936646273 278030190 65837999 15301513 808250693 884190125 347…
Output: 280518345

Example 2:

Input: 1904 1962073482 273322183 3464632 937268110 18190646 166883774 68443306 150919860 269294629 946213973 985870597 409359118 224122278 639610126 252212124 571875444 88174810 103362278 460298157 327801591 275156726 625717821 457020109 733270294 333686907 177312156 759058529 795701939 258838660 818321371 998221069 811461738 685963114 636129720 614793272 992788190 560484941 365504881 703257174 329988887 349966362 148146637 238890987 460536114 570097846 292248657 42633401 945283898 416418298 441393115 932524995 510950990 355638485 20277746 865105252 945833433 377766396 821249535 813570438 817914777 861736222 375915441 719879388 945919684 82050170 946826055 857328817 797895237 795398 540990490 98364417 596621735 953320239 617486173 895862563 311996694 464806771 479166406 98748961 282237138 3964186…
Output: 1962067171

Example 3:

Input: 2521 1671709260 297396904 288774707 349072367 332175805 218165816 84838307 245695440 454727703 462212465 401396606 856631334 347481571 251352894 687411303 711869896 101600951 52008255 492141597 891510896 930296751 817879120 900859157 250772552 701933312 355038249 813274830 138610132 325704405 558313230 185820301 725554897 647879870 537721787 168538723 706904589 589733089 490505493 433677962 683086382 57833907 906274556 655895824 750956391 941672796 947742760 629452467 88876388 385111558 491041513 490494333 669484814 386757829 64377544 122020058 358721053 381404413 513360220 961880198 877104633 219732169 134400981 108302532 738148515 675491497 685378953 492327944 728952628 915894178 114049790 113265022 804452153 738243447 11385834 883021510 138323675 468819057 368480424 352146302 689871652 …
Output: 1671709026

Constraints:

2 <= n <= 3573; 0 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Iker's Nearest Pair Sum Ledger - MEDIUM Coding Problem | CodeTikki