CT51953

Devi's Ledger of shelves

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the forest village of Briarthorn; Devi weighs the day's shelves manifests and starts the calculations. 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 <= 2838; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 2676 -470854 -42344 875034 -409985 243958 377171 748959 572709 526304 954420 -771531 -545415 165879 552706 659340 -491803 944055 246725 -112337 210536 -22238 558109 912483 562944 272846 -621052 -208505 186197 720028 372307 669347 393221 713362 904409 -94330 -2872 437548 494207 -880333 -905052 -855244 -935507 -548993 -42478 -22845 281860 686681 -743828 279500 -500217 -619448 208177 -767213 316745 -442535 771520 290999 246903 -15577 -628828 149296 -610325 680636 -846345 834768 146448 -99344 -88642 433809 370394 833557 67257 103664 -431972 -194204 -557893 -288224 175739 757788 631942 -434120 989937 480639 -751093 204174 -12813 920394 377464 139273 370994 -344593 -627052 129598 -286788 -25463 -316145 41417 -885065 -90052 823499 82478 495302 -757470 635272 171188 59595 39322 719168 254127 68986…
Output: -470855

Example 2:

Input: 2268 -190982 74463 443554 -451344 -800895 262740 342541 65186 -25984 450895 552522 826996 247576 390909 605407 -56767 -321259 701092 130495 372283 737746 267130 203275 -264517 875551 -83566 -72740 523572 -147128 795401 645222 -371190 410052 705742 386106 638578 -573762 825495 -60998 -131915 -899417 -23670 -566169 660758 -514034 277470 -567413 849718 -496729 -574092 -551360 354487 -993111 363000 659119 -818892 747914 -140383 758095 563677 740199 -697794 362163 206408 88391 -79049 261900 170714 814611 916257 516233 -185373 -131116 -149482 -354686 747461 517741 -276952 287141 88573 272494 50320 693781 -658182 831225 -934128 -548735 -950635 -502234 703783 501665 -471721 -952300 -45077 -282591 -755143 450051 387748 790392 603894 -149117 751739 872091 -88310 783005 -2045 -999598 969546 -258709 -…
Output: -190982

Example 3:

Input: 182 -379472 864384 -246464 880210 299802 -543040 169664 343806 -424430 -435355 -135257 790596 648342 908479 837952 52369 803955 -166886 597358 417913 -711483 407651 627913 -364669 453408 -922038 -68972 -120472 -525388 -622990 346585 150652 335269 669594 177407 452038 -104931 107381 -85592 38790 -414118 -579120 519418 619342 -561090 653586 405803 -20456 -92281 -851476 -507128 -25826 310699 -690471 614227 360770 783550 847200 804432 802264 666656 770437 67076 -477539 713267 -592758 276252 18395 -856007 630158 -817334 -242157 -153842 775751 528281 491472 -164164 49854 -437553 -344408 30160 -127654 -527542 913072 637544 192091 290336 -734532 -681365 228594 -229757 -680720 155826 -937757 14035 -316526 338217 293245 482605 -939872 34575 469715 -465133 533852 -348609 -964763 741382 411552 -165786…
Output: -379447

Constraints:

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

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