CT42744

Last crates of Nina

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the pine barrens of Needlepoint opens only for a perfect tally of crates. Nina means to find out. 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 <= 1244; 0 <= a[i],k <= 1000.

Example 1:

Input: 724 1015 797 374 468 746 68 375 594 349 846 545 775 667 266 344 324 546 37 564 499 718 843 659 736 234 677 795 184 37 637 36 674 409 832 580 364 531 279 590 845 406 23 444 534 168 344 854 433 848 590 955 789 316 540 460 814 516 590 738 715 790 834 441 487 374 945 787 233 80 257 822 239 627 835 753 999 942 508 918 532 621 511 178 94 141 713 509 724 773 691 131 669 163 136 397 6 197 950 320 519 753 959 361 737 696 331 711 698 863 194 112 597 203 370 950 720 948 398 121 12 72 11 894 981 293 443 253 79 968 687 717 831 498 78 372 777 56 231 390 977 398 980 649 177 388 677 573 697 591 273 515 870 741 643 39 117 22 547 764 557 943 73 363 823 145 771 284 853 737 683 596 791 14 896 815 447 717 234 439 155 640 965 754 216 611 662 495 352 567 33 257 370 706 114 636 449 256 576 583 291 270 628 684 989…
Output: 1015

Example 2:

Input: 740 1274 870 749 757 548 126 398 128 854 608 87 571 596 826 798 937 254 609 286 428 328 335 62 186 667 408 909 174 363 200 931 752 453 722 546 118 809 98 658 809 837 614 374 196 156 201 684 426 521 765 100 711 209 923 719 878 606 699 422 693 169 370 200 392 874 684 147 639 582 841 485 2 917 990 236 61 655 692 44 609 931 560 315 467 332 789 515 78 278 140 729 752 266 454 989 78 274 803 526 192 830 931 616 779 513 153 313 95 765 802 652 676 570 79 754 647 25 861 66 333 219 952 809 359 288 770 638 897 632 941 799 451 56 961 557 667 14 57 415 841 58 461 420 616 19 344 872 57 537 940 940 996 500 528 488 279 818 678 214 166 637 918 379 116 567 887 443 84 239 774 988 342 787 643 927 878 535 402 175 385 411 86 644 424 386 52 401 604 739 845 628 923 822 977 109 249 592 622 336 190 976 912 750 757 7…
Output: 1274

Example 3:

Input: 798 639 978 195 815 324 622 178 99 845 412 305 595 227 436 576 467 289 25 819 289 527 749 285 880 600 975 276 986 367 539 831 680 912 788 130 624 402 160 831 537 442 889 558 411 411 865 244 784 977 697 905 744 536 564 171 276 548 370 473 712 174 611 106 854 82 148 869 543 162 410 297 669 967 990 733 451 57 934 269 214 126 886 217 369 784 337 446 711 196 417 283 402 687 970 990 514 34 655 991 993 884 509 50 477 383 263 486 791 761 343 255 90 675 234 760 622 799 165 622 878 177 651 355 498 666 599 682 937 787 199 258 751 238 992 154 963 231 14 39 582 110 605 840 823 13 636 803 821 652 773 385 485 296 148 798 181 615 736 756 397 23 330 907 263 498 987 159 615 776 819 353 528 810 413 894 179 570 204 994 728 829 800 713 603 487 364 789 402 666 566 663 807 1000 759 827 343 838 138 733 780 664 55…
Output: 639

Constraints:

2 <= n <= 1244; 0 <= a[i],k <= 1000.

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