CT48353

The vials at Winterholt

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Weaver runs the studio at the snowberry thicket of Winterholt. Today the books show a list of vials, and the numbers must be worked out before sundown. 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 <= 1133; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 778 838848 -25459 -447960 313612 -906459 -565584 627421 537563 753713 -884871 -960013 -264898 132692 -882220 -111194 857555 -982016 795544 -398382 -599519 -383870 529002 405027 -54625 -383398 -616751 -40372 387590 -798415 268702 -381527 -996135 988781 -231948 91743 -629451 -963856 -236934 -461658 -777546 -614776 559026 581362 728300 -230613 -807378 -690640 426853 173745 435624 439385 -568022 -454985 503103 -820145 -205236 -639541 -887425 -776261 421279 545682 441829 754725 905365 -95938 -571547 836907 -503479 -813788 -673228 938299 408158 -808442 -394701 -731825 675094 28851 -759300 -457015 959287 301857 981596 -602451 116242 -376696 -439288 337385 -450919 13869 -951866 262589 782605 -475691 822048 746317 119 307132 678794 -18461 -3034 -428393 777087 -615845 104286 -885734 -982179 -477048 …
Output: 838848

Example 2:

Input: 768 -458338 702349 -634067 661814 -816622 -948497 853063 -494384 842858 432060 350848 -549823 102636 656437 -598827 700249 556515 229316 -412403 -216649 933115 840491 447020 -410557 418894 483607 134994 149820 617471 850637 605142 -675572 -855392 -768958 819707 -947453 -649564 353067 23940 597511 -709713 472165 -999165 103714 355002 -552569 217604 -791254 803076 667284 405903 -583514 -660364 -741133 -161782 448250 -328375 -545515 -78802 263146 -833090 -855219 -395514 -438526 278582 956457 -607281 -862295 671676 -318081 -49392 77717 882066 515777 -52467 -557287 -482356 -718310 552739 -525260 417633 979444 -703762 382265 -339812 -973621 635584 225354 592335 -248794 24142 492215 -402443 -802805 976288 381464 344725 -602418 -915633 795951 -658899 -804739 353322 -248518 -100713 -66389 15718 828…
Output: -458326

Example 3:

Input: 974 394699 591443 -222722 334055 -578488 -89872 -478957 -696653 939119 1928 918016 -351742 780977 -253970 -286680 377977 639364 -475692 -14927 -617171 -323057 688685 -770216 945678 214656 -21986 752612 -333756 -972682 -640748 -632832 441116 450546 613776 256552 -822506 103385 -293174 390453 -973955 810739 -866714 125339 -115144 308391 703149 25073 -642172 -718829 -605922 -628425 -749596 689667 426988 -554816 -621804 198468 -950341 -295882 373058 -722352 885444 671697 -835027 -81609 312346 761914 -285718 -558305 -936079 400390 856349 -685203 802160 -830044 153086 -570200 373670 -214684 591274 -903948 20871 -185003 -786508 -561902 -190472 -317899 -693725 -963710 -75529 137465 -732304 971854 -569175 -833254 -950344 69770 -99090 -389928 -600318 306056 685979 361540 124813 -833877 -31912 -15483…
Output: 394707

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The vials at Winterholt - MEDIUM Coding Problem | CodeTikki