CT48103

Shimmering vials Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Chaplain found an old ledger of vials in the loft attic at the tulip beds of Bloomhaven. The margin notes pose a precise question. 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 <= 2695; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 377 1137238535 241268670 962801408 428414137 846067060 103766488 114141056 109303682 111595484 13714975 210085457 921037952 150312153 175065050 835111720 22982752 811444361 197000480 967969720 206562780 265353288 458129819 380239482 198477436 726492052 393034214 300735138 281529996 677550172 864480876 245327159 342121998 235268518 985948684 104261032 802206727 526523278 468220976 537736596 716264073 976769935 981727368 327072674 141864611 967322875 223097167 476982584 804346264 289917025 189596420 296489658 53209044 219908479 875548131 818752604 898508551 324647703 859281344 313105221 482797566 747848120 800377951 441619631 373478740 34415374 535261590 868832546 319317 543229432 624717570 180426125 860843688 637312128 220893555 586023263 902573859 794540002 505934771 432501709 996887506 18…
Output: 1137225505

Example 2:

Input: 1788 1598248262 627975860 430801538 956100252 93296986 588910526 66956633 743580431 447572063 477573346 704441733 335487131 870965015 251159490 374281417 821383978 429979628 699722364 230462392 693113764 9982266 190625067 449728373 309102244 342817968 522837153 589909247 375198973 336710764 844426163 377338155 680240090 527162398 490993672 884802304 189468185 768936872 436799355 269297894 878568322 665406441 593362780 205100384 448646724 545428639 166717440 609892268 85496186 264987567 52303715 693610465 277045530 413538723 788887563 102678906 725925820 940691903 156981723 681185056 450628112 482834521 67518516 332730288 557881572 780978982 905093529 763826615 423451191 408103103 722352923 624560307 743188656 73127532 367868054 267673896 283472573 709484226 8122856 952523404 279687381 9656…
Output: 1598248903

Example 3:

Input: 1918 959239046 984556460 631770085 213924863 933052775 98230905 986990757 934213134 397553766 874318828 718346031 329524880 989681847 273295772 593197692 916061556 686127287 412668635 780925336 719760414 285103761 822089850 625307374 446283066 634746582 840730168 797507152 975188132 970842160 220740770 928954847 556584926 830518633 572524809 890782184 276244323 652666626 863854310 110250984 561398546 190952944 643617367 691772014 794984868 20002481 956331930 959281155 556890082 471101835 23489461 199488677 481143164 961397236 155308041 601482239 260794741 992054497 789548682 676198509 730293409 251883121 376383644 462457318 747685102 444810116 219681644 241727194 84578142 99364662 775160270 524505905 38582323 338555777 28778979 319076523 705531316 927324408 283940021 757306785 722332098 24…
Output: 959238607

Constraints:

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

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