CT38226

The registers Nearest Pair Sum Puzzle

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The valuer Chetan has been asked to chart the migration season. On the desk lies a long table of registers readings. 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 <= 3779; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1845 1344907486 378132741 290811465 543648408 845600157 885841407 920644440 274610216 654786617 100798010 755801793 559850497 924307143 767286228 6605812 981404640 11944283 729375204 800141807 275583913 766782030 983781921 275557800 427406272 846702117 538039858 812526767 494255036 56730214 50685640 418565778 955817536 57890270 294133854 102650008 140052576 370867477 298038610 157547649 312388342 372432697 369285174 41351462 594226594 476028201 948699310 188869088 91247651 198629427 446975052 495864799 529917128 594611879 458939359 160930418 57429731 57276899 111390145 719385839 359049796 194722616 699269810 670388210 265208593 916965403 532053371 31033572 879949096 143104552 631363694 757571566 644038774 575642305 34863126 583401703 268852893 708278178 568828401 287753174 460592920 735755…
Output: 1344907881

Example 2:

Input: 3524 1613138769 8185777 417995857 215887811 489827941 802663154 230692254 977157832 779837156 413542485 685602472 158349783 283843395 248463963 675807311 300436427 568751918 98027592 499870733 396874496 718978483 2158254 957710475 999579451 186096231 681823044 540709660 153238143 514449919 328206348 526450391 42053015 732133892 466179447 856028205 85133769 65589142 18554583 210964590 89820883 517554201 165155955 795611626 245599238 865485406 109495362 571637795 652849 894029583 847532646 969890817 5410741 55603322 130705215 280015450 760509781 43958789 555148963 972986929 754366143 166492988 115766278 893443184 779391169 842855397 972399837 352604591 964610583 994570853 832713793 774718067 604091559 311579565 490198637 843389145 795034028 90077683 320681954 934057599 854911955 100651686 63…
Output: 1613138794

Example 3:

Input: 1100 1274881291 59100228 740405331 405066178 952195063 232413692 699772784 214006438 665083748 206975028 925441681 212213983 71895673 329509369 746272369 434610191 760835897 58287828 194214670 89818944 539254699 147389956 456676956 70737303 110129075 533193020 94681547 428021437 969821176 578368445 462956682 452463389 845803136 107023875 683026227 397622723 161587870 383272506 166956393 799084010 229390244 804208709 140720540 522100827 341978452 154377929 19290808 830308692 717450038 908276745 685387432 668561399 546787505 944324348 231957706 5744303 990644203 671853833 293808417 765661612 226724600 126067541 450811455 274820794 564659831 476660259 110189658 780076331 347732935 496327742 662825100 985048139 570026765 806765542 903687324 201967197 827927322 980923492 80038 776283475 5656483…
Output: 1274881183

Constraints:

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

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