CT43504

Last ledgers of Brewer

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Brewer runs the foundry at the snowberry thicket of Winterholt. Today the books show a list of ledgers, and the numbers must be worked out before sundown. 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 <= 3597; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1075 1250689892 -46793465 195378074 -679184785 224289319 36231101 464002408 218941228 -179132546 374383512 -961396651 -467877734 397887442 713491147 448266900 -946207998 222070112 -483297724 848276677 -431539048 -396948467 863197558 441733902 674403559 -807651155 -922842993 -763813089 -903775984 -539956134 495593039 -560733530 -6263146 -168237132 -433325301 -962352512 408189175 -548287638 29442911 -645634718 376875867 -322299666 935791214 -152003782 341681224 -434401359 179849139 -804049152 773396724 64709471 838493446 5876138 -726260888 -918631352 379990153 651613957 -815980189 -63849078 437200510 -664946463 -366797803 333330157 -233527470 -45294954 506832401 613331539 -854468018 -984763718 -23276033 -291537216 298837347 702960361 550722545 431887521 156783186 -194018973 -556157966 -94765…
Output: 1250688634

Example 2:

Input: 2130 233631037 -366382206 465182953 887870943 733897929 962149659 -653616654 -649904721 704915964 999595563 -426105803 -333634436 307900547 270808212 -934043333 537282648 586887537 -134073813 -731990928 -719436708 119779552 -568760952 275332985 342675732 817551086 139176545 -281970800 104177134 -166225048 -518284217 -499641101 934515055 -555005810 -53639148 306767285 -576690439 -863977293 -286315459 -162009962 -623910874 434398254 -243054073 154845289 18976952 -701286105 925915658 -602192226 -22449132 -108557256 158670006 24111034 162880 64020734 -806582015 -192027556 550458642 825960152 -754405570 -566873885 -294038767 -393548960 -797454978 -628524008 -45176864 -506133760 -876549679 -359914502 -103536376 946482927 864604267 804704116 -311516165 -442041587 325672939 481129244 130236786 -46…
Output: 233630648

Example 3:

Input: 458 115844084 872539615 -59581106 496850597 -857342003 133297704 -416022366 709471094 661905783 -378015131 -818249920 -814414045 180718437 -591769744 699100212 -227924502 411415701 -354733077 -764209730 349780536 -302511997 -606797085 901442131 766722347 -351853627 425803494 -397161401 -865139678 -865656402 -35540473 326733883 94144733 24977060 -710117612 173868900 413272873 -403541509 842754562 -408633046 -519220982 -134794731 610566994 -353549695 -496621241 965040567 -989438444 362799871 -563477589 704615162 552692432 -176980346 -445276409 -589228216 790574208 -169948029 -610061150 667365562 -406457150 -266316612 -135586709 925157034 -47181978 438807194 477574839 -13733763 456603908 -265468450 967008375 986316346 -26858058 -982916637 -953957969 57888764 139734395 -159160405 -127912224 32…
Output: 115848955

Constraints:

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

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