CT44310

Anaya's ledgers Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the copper works of Verdigris. Anaya spreads the ledgers records across the table and picks up a sharp pencil. 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 <= 1387; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 1270 -390902 24181 433594 421827 -282587 -164825 788538 251662 691465 -846998 803168 956054 176270 835731 81272 677120 721080 472110 -814234 13028 -979614 741367 -140646 312424 -479726 -277735 256522 -905893 -942630 691545 63241 -691522 -794329 -743222 257025 -823758 -278803 60422 -133308 -197960 25906 126732 150202 -881771 -60607 833612 -143984 42943 -983505 -606267 475854 191036 94899 -431041 -467863 -36454 106115 -308833 -474395 765400 33177 -243909 284635 -835506 -279441 23503 -759034 -753492 854938 -887929 -719417 596090 -678308 553124 226531 -103144 471934 -940587 -544697 -72787 167505 12482 -544821 -1924 -819491 397497 -368371 -987049 -508244 -372401 260793 -193600 123203 46212 -582080 984468 -894358 -902719 811109 -137040 -69659 418742 -784025 -501820 909838 -235975 -398227 342141 …
Output: -390901

Example 2:

Input: 1365 1726597 -967676 -307234 277375 -684289 -152095 584024 -196587 113653 -694406 -696406 554857 712839 132772 -648892 738897 6076 -795971 87919 -697885 977102 -813866 290441 824434 633979 -681152 -195460 -571054 513134 423034 581220 334980 -123091 930424 45943 -482173 -341003 229106 548379 -18847 697031 1191 -465756 659471 -185720 -91509 -160678 51513 930843 416091 912280 -168950 -426938 -293807 76909 349952 -885148 -973342 -809952 -67646 437689 -728413 900225 409031 -464995 -215738 -983699 47436 -72227 -535457 -757257 -371767 73008 -493030 -429823 335228 -913404 -749240 997329 -882360 -853382 889468 -802247 -844272 106644 -494468 828588 313747 360944 238271 253425 764655 516361 359281 102394 306198 -642359 409383 668054 -833252 979536 -844252 -685777 497625 916523 -945281 -34063 507330 -…
Output: 1726587

Example 3:

Input: 928 1699349 -967188 485537 -288125 -149025 834738 11067 -248850 53053 -673012 714610 902340 899641 982286 562017 -412321 -325469 -476598 95990 -452906 -700959 -882907 -681854 -583501 -146763 -24944 32854 -973093 -487299 -191852 480854 -620831 983212 -819053 234257 800309 -162429 807691 756382 647209 767602 -139858 367942 -514649 294458 497290 -837891 -34378 52312 -212081 -992689 -542441 24249 419844 -896982 250417 137429 -343108 -331687 -894015 -611118 38166 840009 276408 -167728 830241 -37801 -889916 928794 -235615 676690 -260892 -137055 622945 -399424 -708396 -85134 -449804 831913 -769569 -286058 357063 610557 57150 658372 -45862 -128919 -415065 203778 907922 -200101 -881899 -824218 599287 -316862 850110 476516 -326867 422591 -785210 -938711 -888854 -697451 -525586 423803 -55875 -179793 …
Output: 1699291

Constraints:

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

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