CT37761

The Nearest Pair Sum of Rushing Falls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Kael the registry keeper watches over the salmon ladder of Rushing Falls's stores of shelves. A careful computation stands between order and chaos. 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 <= 2049; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 879 142938750 207144014 703682022 332924248 139722911 121996014 872885995 409278921 953119084 518439665 208304007 222364516 982370056 119885659 700311613 108239915 65716763 471181681 876088826 23470432 389369320 273070692 405911418 630466727 381681791 208858609 3449750 178546200 918633864 983298954 293988397 576257365 882381842 157901612 95538539 199596654 796822629 121213159 997324765 256481914 679417020 600295350 484776723 651978340 862081255 627321471 236766518 67253939 639808711 720460498 214145804 899448810 470672019 158334881 406560522 653920816 32538534 127094279 836602712 20517834 970869429 353388300 255542989 741316402 637838611 627943440 372053420 980717581 575634552 154054240 122872623 554939691 442160320 882822944 396557138 725069498 118289648 947543540 776205294 512712058 9978…
Output: 142937239

Example 2:

Input: 1100 1615335647 198435874 966480902 964401912 194775333 445368180 378480199 669118592 927887008 106274171 282807630 775160122 487596015 503662192 99520230 525827998 210565938 168579370 326155721 498592122 994362931 789243285 588876743 100820799 69736990 802809610 126454890 371548329 882925472 634784246 651443963 833085352 168771069 163465987 93665317 812741632 650228441 914357601 865895776 381981788 380547703 944346704 752075508 117945570 302276528 817642065 904021371 671295636 515124601 147521250 139394229 141786987 28840320 7889643 988131368 539855309 394091090 484703843 333851730 440214541 316206908 432630542 632388410 438314583 452491133 406259957 78808981 981137620 911877543 180930722 117994152 919703961 543780725 655351613 25042675 213701358 368952373 593282449 106999567 536222473 94…
Output: 1615335224

Example 3:

Input: 1684 318675658 988446288 45736117 910886779 173231075 315928697 468228401 849015314 691920945 18427329 564902418 433193674 275157947 767662002 823461162 911553807 150574746 83590333 812129361 827987278 219967790 893601451 193323310 313067671 771099708 6190042 68607347 346175347 853331826 408860936 97897156 276834748 220084853 395815912 248767155 160526929 850284693 219322274 374205901 367259609 241794928 638028560 865775882 303337767 631026469 100829843 659249927 147852440 131466727 548008567 45040185 550609125 455676906 922357165 868708351 859830116 200160975 202602853 805169730 747850805 608680365 742403179 620119584 984427788 31394476 784013563 708683949 482235233 931148512 620371081 354125092 782071788 312819871 905311972 262207544 28152946 494560252 460892559 242102928 178561660 79000…
Output: 318675411

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.