CT38031

The Smoky shelves of Ulrica

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the dune sea of Caravanrest, someone must balance the workshop's books. This year the task falls to Ulrica, armed only with the shelves register. 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 <= 3796; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 3747 804179067 418797659 904940607 744134451 188472826 621063063 915720339 972650789 291027421 468676789 944748040 869891878 351758353 280933455 420404254 708203409 653348243 479588401 718081959 963203329 871604450 16380069 851523085 676188109 54549022 221570777 947947653 579162470 413062781 688079517 673645393 172541201 722546017 169417988 659693868 479138721 671044448 201201640 156625317 30785271 244836166 489777560 934103013 467956720 600418768 837930199 604589898 733006509 235247500 361133600 140377900 69447773 347059035 931628435 989415427 129496910 166452898 496194972 755029529 987490306 502729049 104984500 105752756 780492738 937869657 854596047 970428386 729884837 794390801 403127957 350977933 977421841 31408509 790567867 834218639 450035555 38457849 52491709 670516464 384772846 92…
Output: 804179017

Example 2:

Input: 608 943793718 997515942 657832994 483676792 257107256 56257251 662863095 993018802 885567374 637091946 93999192 512299963 189138940 430532604 871620668 332426025 108622995 346504340 309517203 603226783 414372343 484566437 906481224 650577206 218625033 110475004 299056674 181222649 177316068 736748387 287678758 823786259 353999923 937073277 924346366 585115078 406643059 311827511 310886430 189598896 875804885 977013845 642479941 52715631 815272974 59131522 249334284 534029224 989822246 486077561 882869274 741854528 45268389 544427579 765930871 507244918 573392557 370398655 654706826 630983026 656067498 21115746 358982900 475847514 698189639 248367849 335599145 906801133 123971681 998780234 596694871 978686091 861374388 293036538 828755381 382185195 48258063 865982641 526014173 556312463 811…
Output: 943791384

Example 3:

Input: 2774 933392830 672089501 771575938 27323089 832554456 990950413 23329667 863846408 211572593 925779435 614005631 282549686 852566115 542351199 411675856 239765999 335769258 322798028 440023109 476723177 408739789 858609004 509359550 399877719 14255615 167471516 119873833 78615043 789440582 791277426 969225833 531455050 45538971 844791264 25293351 473709721 82167033 318716178 578461408 319095749 612788881 703989261 291753943 474562081 656749586 311528506 973106767 390588051 830541859 859496688 26714232 876402280 470565242 486642609 717208022 540826143 390850015 481984577 470142908 329992602 847338028 548771153 956153273 443325987 836121208 438473023 247628832 521820338 701043635 428670865 102133110 836064063 309219990 345473920 326314494 316266435 448364467 746630258 40614234 114459809 5349…
Output: 933392384

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Smoky shelves of Ulrica - MEDIUM Coding Problem | CodeTikki