CT33463

The Frostgate Nearest Pair Sum

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Every season at the northern keep of Frostgate, someone must audit the season's records. This year the task falls to Lata, armed only with the weights 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 <= 7230; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 688 1973758 234992 976952 833859 -133384 452451 788995 -933467 -345488 692713 -781682 -63959 528286 606039 -340805 -233154 -736746 361955 287783 475031 188137 -3242 860248 -442262 517182 -747986 188915 -339680 549185 842120 -901929 -489737 794434 -896792 304501 -225850 628416 -96569 212106 260029 421173 -262107 -89741 -707358 -769455 520738 -808859 599523 -658065 -881765 -898474 776826 718211 526745 -435885 -761952 550272 448595 475148 612986 -384796 123696 366540 764511 -203929 -213504 -313661 860267 720301 780482 176153 395819 -735580 -943588 157941 -430917 -665190 -232836 -349304 655767 56203 64835 -486232 691659 -341719 -460839 -26600 -162043 -692986 426386 -473834 992753 -930738 672140 385529 -25349 -607139 -218110 -11141 -157599 -983644 -713310 336485 -522601 -480832 941869 -621490 -…
Output: 1973890

Example 2:

Input: 22 1796698 9436 -100009 480521 -49331 557819 -77613 743228 130011 408763 -316053 -432424 16793 -736733 -724232 -297916 801858 -582838 -844547 -760242 355415 589718 971518
Output: 1773376

Example 3:

Input: 477 1270693 -946024 192648 880836 -635001 -226251 -50349 30724 -877148 558252 -306075 -897452 157023 -171680 453696 952726 -660857 346569 916083 752750 299063 -67174 -240038 899322 538987 -804410 -431136 -294592 556778 492437 -374925 331051 230041 -322985 517108 -417275 263723 -870258 270070 -470396 943012 6844 674565 473772 497091 30762 -66444 806235 746252 319675 718662 495439 712446 435961 -273770 -726834 -184403 151238 -305968 858860 769448 -892902 -260249 -925562 341101 311990 293541 226322 -162082 870432 836108 -588504 -436028 85529 916299 -408336 -123337 -697845 695762 -116290 -390546 12313 997993 642349 499330 -278317 579582 -856742 -226626 -615493 -61696 -184528 462012 486703 240287 -529907 862844 65109 194576 -635794 -556575 913207 212770 630578 -533835 435040 73190 -855124 -1835…
Output: 1270698

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Frostgate Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki