CT49435

Koda's crates Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the steppe camp of Horselord Plains with crates of crates, and Koda the valuer must account for every last one. 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 <= 2281; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 1217 478934687 283703336 52911779 364974857 454820853 653276872 807385857 628451866 574936397 859896524 455802317 819644969 702984057 332994111 925242297 4588286 238702515 111579738 918616632 7334316 659029074 469913940 138270483 849290751 994197413 622547443 976506704 192506188 264878924 38096699 862748910 470536751 990623284 103139828 920077433 717109563 671769743 991029082 907962515 145752711 708048685 716598901 644994164 728858758 119790360 251318398 245053396 329578226 145847478 534513060 787720312 759582658 970824052 336254087 895772366 703264153 854795489 201896425 733730197 435652143 972114744 98302814 617467692 86457410 408640758 213319097 736487335 935819867 379916124 329983420 926898912 925382327 790973393 264595311 809901245 914126234 511751185 166846916 645773412 768113569 493…
Output: 478932815

Example 2:

Input: 1576 187739286 518937202 114430940 528738812 996370406 640338107 514606228 68150201 412428717 451809317 724280138 817069981 124430595 194810833 178183190 725552220 438240317 648846393 139023540 838510935 775963176 545494841 24683784 684206945 67212440 136085497 821267427 887116686 849763384 385307954 358141265 638476785 498218775 637518459 565109540 346038286 405895412 971104797 188884245 874537830 235965710 290684914 538420022 50817028 120335285 825367171 8861435 29055930 529058241 38311876 979415558 184270135 643475537 748690524 352969954 206761608 343243938 919502817 470109855 588123984 805151730 315445155 798759095 224243731 350418502 254524957 10472915 339467350 834979540 39937042 748299480 703627647 828640183 680738535 614209245 17494674 858450187 371052417 53904455 299461036 9500367…
Output: 187739687

Example 3:

Input: 1136 1096406747 703947861 485223230 322352589 543204456 352740312 150770148 772577248 327988662 857734021 781202165 313278857 511060416 481203575 384244143 384244493 169891602 821855519 643029053 326498254 634424951 468309090 502422849 116049610 510700816 622869952 77245122 3185000 76296822 280740469 703113877 576324458 406379095 279699444 141591569 60368866 251571972 592631803 262022249 887925453 829333945 906627451 459794978 772193553 124415479 675174468 163523974 178501122 126127082 155004701 115541343 608849405 526118247 625175824 289618315 524223874 511156682 561905741 517411298 407675491 381813509 957223818 8617521 420479193 27260722 943997342 621642905 576625152 930657141 674694809 992336656 77667703 737014203 538700912 57326159 944724671 625105227 494762802 133611644 509714223 6283…
Output: 1096408005

Constraints:

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

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