CT41829

Frosted registers Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the thorn maze of Bramblecourt; Chavi weighs the day's registers 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 <= 1955; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 321 1692932412 541265261 210345167 703220509 208280368 533823959 145463560 826880305 340343261 628355722 189734153 215374777 795734489 151523470 868332224 239472214 180256161 958847186 930726689 87850679 843174118 36581485 79000988 886147716 82902696 522345342 882702350 819657554 907406660 287005867 518831171 172225870 406906961 128461313 387967383 942731779 964273958 359863403 102993145 206865191 950595217 820886682 494399940 588964670 105229788 969800359 332810581 13664980 550808446 939776310 301211865 331056384 760742699 584892047 706738202 812579674 626203712 121090786 824545096 813922828 778996570 158562975 250779507 225241561 907229231 846777151 976975608 331158023 577296744 845129835 568619029 586360327 723120212 944693690 997438887 316438430 3803265 987242922 241483649 880072911 97…
Output: 1692920571

Example 2:

Input: 358 1203343337 82505272 540942300 574441340 604184899 452448852 531928916 531286217 953707486 109977458 463014508 76167702 445046172 810398367 77930466 378945614 169312145 379303197 813322556 12908018 794999419 12908378 920496518 481447586 495180849 490016520 828676098 138500430 318948440 823819283 245829874 53618136 556852585 872625241 83052471 731403286 897510252 500815081 325261626 40142544 864144142 168640787 408127991 443379695 609786101 837285976 510416187 814448019 480596746 564887820 279845728 627023649 290658273 919542889 444884233 277261257 876740533 970139402 432599039 439996498 488256148 477621967 256129113 347576923 994562654 590082542 603346131 224984835 788306884 831768970 749577357 45533918 253785725 368931150 892044013 112097543 719702407 741213252 461291004 881190931 5091…
Output: 1203363294

Example 3:

Input: 923 1171280078 648267385 533371403 611756969 942579440 91745723 924589156 597259500 165046925 621153056 865122201 233772927 293985127 885033800 383765424 740239955 78611440 766833557 918900487 727245316 28672454 432017089 82283940 931503766 271925322 759969777 686089221 34027046 154044429 933401647 640764655 361911582 271148151 37133245 683692390 177697950 492520806 317754076 628283596 31190562 790703812 149330724 730723187 189570084 810074347 842405766 758919971 175312877 113682470 515505624 957835281 568937531 297944356 231791729 304595088 198840321 919094856 682567369 866333362 243446650 715104289 101706163 694892873 481257351 680785914 190596364 833773131 999118165 479552596 763252245 15421915 427993916 652282205 647621280 592123684 104666175 972972156 362630495 707802097 496703535 428…
Output: 1171280336

Constraints:

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

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