CT31709

The Secret vials of Nina

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Before the gates of the tannery row of Leatherwick close for winter, Nina must finish the vials ledger - one figure at a time. 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 <= 9881; 0 <= a[i],k <= 1000.

Example 1:

Input: 5890 491 878 712 721 444 696 130 364 434 59 414 339 13 260 220 581 848 695 414 556 252 526 253 210 747 351 609 205 83 594 772 556 856 491 839 264 555 3 228 176 916 582 270 113 244 362 518 216 942 815 20 981 928 598 291 696 697 297 287 387 385 22 554 946 769 230 777 405 474 210 130 350 938 466 964 119 88 472 64 557 891 727 132 82 376 682 862 166 413 798 323 285 536 446 727 472 922 264 180 603 349 130 483 132 957 301 106 273 233 815 959 751 403 860 89 204 703 800 667 949 445 41 700 181 393 810 776 849 401 564 449 472 637 939 202 346 716 986 883 266 569 753 93 86 179 839 475 442 746 611 713 197 38 222 304 479 946 235 477 236 266 304 918 553 834 141 414 941 295 776 353 983 69 181 122 306 830 311 867 847 616 117 664 711 547 345 592 747 344 584 609 88 693 2 967 108 608 50 936 571 602 824 216 634…
Output: 491

Example 2:

Input: 6470 1002 938 641 972 875 528 941 219 879 190 788 221 678 806 64 901 347 303 148 22 68 440 943 855 936 817 227 408 147 506 256 616 435 227 878 683 334 907 620 199 57 502 630 617 135 992 263 852 280 696 402 843 508 987 921 29 856 560 134 851 821 996 593 235 120 13 999 499 3 674 943 316 681 362 182 620 234 414 970 674 561 22 995 332 77 266 233 777 777 112 524 359 523 262 205 944 813 947 571 237 907 319 308 320 56 629 125 191 208 289 535 725 64 497 495 327 265 159 951 930 32 79 506 167 35 494 744 803 1 245 971 492 412 784 446 466 196 940 928 953 140 582 480 391 33 462 760 164 487 398 893 151 8 335 163 37 168 942 454 698 664 231 615 60 262 350 727 698 239 671 374 425 659 175 490 755 691 20 757 955 15 388 158 586 754 636 430 56 809 229 601 479 212 100 894 146 837 776 405 293 281 242 514 346 886…
Output: 1002

Example 3:

Input: 2398 874 809 584 249 15 683 102 822 379 481 348 599 57 67 518 836 1000 88 343 467 578 629 210 34 472 129 579 144 72 769 699 569 712 65 291 201 135 399 590 669 209 284 563 211 376 555 100 193 519 174 902 262 642 751 895 656 132 727 447 468 355 794 447 650 676 459 948 373 922 96 389 872 283 921 787 222 875 793 609 176 316 251 2 787 345 825 624 111 905 687 720 733 109 838 332 432 338 362 306 253 724 928 856 418 697 98 826 640 486 179 482 224 83 854 90 356 690 419 935 800 896 309 453 769 620 887 932 958 623 611 513 662 19 544 898 566 130 775 708 559 62 133 791 226 576 99 262 409 582 724 325 602 618 889 635 168 998 762 772 151 791 328 700 24 772 426 905 688 418 194 524 803 707 869 598 558 313 351 506 395 666 484 619 604 65 134 302 750 749 946 407 784 785 848 5 922 682 971 747 424 891 115 876 58…
Output: 874

Constraints:

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

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