CT38267

The Northern Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

At the island market of Coralcove, Bram records each ledgers in a worn leather ledger. The guild wants answers, not guesses. 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 <= 2355; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1448 584022971 440988253 670809853 686970004 106387370 52208209 318056521 339342528 618778993 451003985 779379277 700632599 221597180 243630554 536156726 150459430 615882680 30906204 816352840 116230100 497229420 315558094 817860004 578471931 984981367 930975298 634028771 479762275 188174284 490359921 353703613 90527947 466105639 509264365 823614143 934795518 638555925 612807724 932215929 968891388 265164401 949827644 515409914 982526103 769347455 446874154 797881806 114049123 328938899 259422272 574276421 595330758 329428937 885643114 125559381 432720599 857622904 899320570 33502250 489494967 748720414 430144064 260828978 338262368 220083375 182266755 97009225 146238396 677953019 332965272 746714261 974077974 78417014 849924001 11361416 561248169 466088877 900517895 408675002 560908310 45…
Output: 584022721

Example 2:

Input: 1527 1026524113 100425782 262235562 579911002 709316656 43599654 787296742 140283316 383223358 974893164 748052574 263566845 576026182 415627887 31707416 387053412 237954509 773369463 565871784 39345623 69269522 542838969 992907110 834923250 163834422 427411027 117529606 12661014 694287842 342465620 176362266 131335704 64483347 219633457 961887579 667983040 386415915 12804541 306146426 482767661 265951139 916881781 123919049 82446423 692768746 477208765 779759068 653457139 561571397 214063313 424289187 843195634 728557240 349420677 14882385 539537259 980009651 977325081 16351863 663817234 31838032 986226713 543083227 928916897 257586179 714040023 836432630 711751828 862624122 767017375 424795665 267900976 78347194 473303025 419080602 584237949 286914443 616594960 864786795 856893915 875239…
Output: 1026524154

Example 3:

Input: 1051 1758182763 678676040 214494525 548766740 489333275 481134255 303559486 260459940 933599190 113695322 752014298 94382162 187673599 859431696 215686538 409667883 628379693 12042184 276820073 804491638 94145563 925042477 350985949 37837544 911277873 282773779 184565138 94518593 697164005 149540015 687263854 855981101 494082489 389743507 145671641 189250133 4624063 628596303 178568053 804644296 393587479 764524099 348358278 397370755 363490396 286063209 989715743 310320025 81603557 854107942 102869975 955291462 916964695 142879355 632872907 244197871 953647931 735536855 978200685 74525180 957223198 732193157 318668236 812474565 389883177 56204691 945851225 958180362 428278964 48264528 203693844 892828416 891654586 273339534 641060821 860764724 679921642 516321351 916957210 117067872 73100…
Output: 1758182857

Constraints:

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

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