CT54171

Viktor's Bright Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the mushroom groves of Fungaldeep opens only for a perfect tally of registers. Viktor means to find out. 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 <= 1244; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 501 1108943228 57393266 129265994 184237701 444517867 743913420 367468490 856411898 266906965 63088153 499207446 886950112 195553587 31647396 835788638 186454152 614563945 321921197 306006809 249797339 376454702 838255773 810279813 571160781 219941490 904837989 86671389 211955844 435312367 971825334 355773384 97288082 517929687 807296338 458057380 658098793 212838996 525876715 215257050 309034911 259640215 953361337 923302202 556297589 987155883 92254049 722285214 168372719 559651400 443476241 276477406 316717297 272035653 994626897 701136647 18547546 303014486 70764970 831488894 974283703 756913446 139921529 799708281 78863185 248717223 861764244 874500162 63785958 939302409 603056551 308767581 861606117 131354830 782131499 27314319 476444543 932809630 310819892 989774217 200316311 127574…
Output: 1108943787

Example 2:

Input: 1139 864248289 636837036 506994892 217889060 168413897 54759245 362189379 298064016 955241153 885381564 745136989 929749414 156457562 530000590 60340620 356450128 781711738 601279290 924150853 930829555 149261962 106324525 727129560 77077964 942934638 847891380 855737907 200296895 995615166 271341452 310686549 300446304 747082390 386826801 71577421 728971343 423388789 966440884 929546482 861439981 171296338 922693734 906109326 893596534 744434670 956762830 585548658 666454086 316481588 734392534 613174306 292611958 111512873 491782522 573190668 945569467 900196076 425043290 33966931 563572492 11239844 807888850 131715370 376846492 455272496 485598562 919048823 68390728 603059935 79766199 118136483 637110013 653617256 293190845 781723590 358753781 937983029 159960200 418770728 466926288 810…
Output: 864248584

Example 3:

Input: 617 965731067 563409262 692839306 77978976 938950907 671939697 691561578 142303626 940870588 376632914 650306423 264730786 453124271 202120765 649422872 131038303 951807760 455434965 237335757 165999218 709516970 520099442 78886605 668428170 356466257 58181872 96762840 469331960 723992838 272396482 577002517 541441442 345401662 804017427 437407508 115471626 609224876 177068358 581330192 268690370 907650980 855988583 154528210 300325860 951553778 870745154 314059514 674079074 190300919 628804561 818019530 859225122 180603942 925553980 841733894 818172876 736679125 235408489 961444920 705611513 126718179 37477404 602092806 184447963 514147183 9600127 424379181 771147263 411240883 231400736 709035285 931030808 708829024 312175208 518194595 949853318 3650910 419704868 493340835 522104029 23250…
Output: 965734298

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Viktor's Bright Ledger - MEDIUM Coding Problem | CodeTikki