CT44536

Jeweler's Ledger of shelves

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Jeweler found an old ledger of shelves in the shed attic at the beacon hill of Lantern Tor. The margin notes pose a precise question. 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 <= 3838; 0 <= a[i],k <= 1000000.

Example 1:

Input: 2602 1469321 131874 72616 554152 874843 664934 103849 726712 532387 984326 545584 213993 100122 459177 508269 114849 305767 69825 14489 515854 152104 88264 155569 201913 173896 41070 873225 539045 171157 142721 343081 545113 572344 442666 735748 422170 831642 270593 444242 33643 796934 248617 752334 398560 20471 971594 272666 247243 875478 43672 670400 584578 373184 953413 599931 698634 40229 658611 199897 566411 559376 721211 96228 48274 258734 535847 654093 581233 195640 86229 5075 202560 919988 145470 316828 648440 893709 194982 981239 642048 417319 815117 519564 368790 943597 682170 72469 398362 986928 128623 934800 447633 480622 669120 661098 168787 717419 323368 598507 732621 306020 248350 637327 224920 637974 794504 935132 715102 502764 564051 107078 526934 216796 797699 421201 8201…
Output: 1469321

Example 2:

Input: 986 141197 682569 696078 673946 193222 293867 801427 749086 831230 86640 794404 538619 135375 929164 212591 302491 962031 170721 560554 584692 743664 147779 845792 960046 701715 936958 311944 138718 534051 310227 389729 982541 561906 50472 170365 346001 719807 728104 269660 7310 67266 701430 416231 226202 783613 87930 130133 378031 373456 295946 528021 368607 549399 195032 810479 488895 898960 151016 568642 179004 875307 729697 71255 462390 644871 180898 65373 587961 204162 91164 224205 725466 592015 554850 821418 962955 986087 765111 885625 108126 603250 946616 807501 220478 81128 75267 812064 225518 172165 270049 753051 977667 854521 201376 647075 20967 384003 167150 378552 666582 485971 384625 868445 128654 391875 772509 249536 399495 495172 158417 170093 600842 852538 924240 198892 487…
Output: 141198

Example 3:

Input: 3343 1772635 79564 724536 661811 634315 385946 631762 221557 476892 969367 692488 725658 337852 92362 199487 597365 547987 4553 245064 428724 848276 562150 726130 18823 583399 470920 106411 562672 536251 491837 157800 944911 535854 367990 441930 641131 469695 508192 698494 369948 281143 811166 792217 324576 74845 500367 961636 728637 125246 261003 83103 369891 790254 269980 718303 431979 906732 50733 368633 725275 818425 763492 769745 479256 358747 711355 880737 137003 994 728549 631473 526740 739972 348288 307834 693287 221315 501907 227876 526161 573754 401164 891080 83610 705861 587587 466711 394069 377688 437883 297724 810414 768261 371401 257733 571295 483506 121447 211974 840447 129019 73292 988568 845832 953210 380970 881392 332966 469956 285514 502578 618056 512831 355440 649943 22…
Output: 1772634

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Jeweler's Ledger of shelves - MEDIUM Coding Problem | CodeTikki