CT51901

The Misty Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Cressida the auditor watches over the copper works of Verdigris's stores of crates. 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 <= 1967; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 1455 308350877 927614377 327902951 44712903 219888000 96557667 122403063 370433914 652482185 661176823 336863364 706035479 374818317 755754516 680253104 289368717 333242534 802058788 383415884 826581906 587018129 347099180 801536297 419746538 7526953 85949281 701668659 408162557 931304127 895443695 485582321 534587209 694280679 142261331 606614206 956074942 491495526 41948562 781962070 351151244 96414748 581687012 193970997 964348169 403864942 754684183 618578711 864973126 499796061 993940718 959268075 634540789 744571454 424330321 108223766 661543889 745488152 393221556 789474084 151996094 295605030 745366086 459980749 11809474 110556870 918043698 702825836 769281628 272273702 314202570 330392296 615297303 989805351 66755388 518791244 643327743 619896177 89077931 27237854 150264139 365425…
Output: 308353199

Example 2:

Input: 274 1574967798 334353380 75417295 191255761 384991249 685752729 480898103 282266101 399285237 907545441 628725196 639517562 980206895 585809043 21326632 212018780 293673754 335726748 318511975 40693572 411289087 192108805 697812460 328379120 848447942 130590277 902786950 887918390 767304019 83364528 824370039 535211142 41967580 756257094 516993487 504267664 93018121 140032574 633494705 190102270 198696060 1662507 866279349 652290491 421029010 688887730 583739829 28603139 357033515 727661430 236510585 226322265 242722214 427496515 360436696 851826078 451414533 964576718 532588210 461325481 665343750 894106997 608343960 369142463 251179369 43801248 587080556 952742233 4453973 387096892 923763410 975406147 39941788 632042355 778195040 651867725 538756394 662742906 224879510 989474168 60869622…
Output: 1574927908

Example 3:

Input: 1660 278951401 436221316 192031686 599649004 992829761 827479599 603587106 712342755 167444729 753696038 401993250 577347032 442882052 915267143 620205039 699131243 508586191 141990640 926931978 660942521 894667199 932791360 402989298 210512438 159350622 821671589 136655821 645940329 442927961 505988035 643797828 990830941 313698320 532327716 998269357 778358584 505354461 361726342 220316093 769309362 321107358 579373549 296420196 985775433 497675191 178097583 397911328 604904287 505256178 491710001 760859687 932371326 556055935 991271941 704776181 298573095 958760402 167140204 794751285 206278586 110217028 92937234 331682873 298040944 222706845 906883199 252049624 138536420 985639259 849554642 825781613 376176060 135445629 883082139 218583685 890443356 860483490 801811224 750618425 497458…
Output: 278949614

Constraints:

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

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