CT31059

The weights Nearest Pair Sum Puzzle

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Yuri runs the loft at the port of Emberfall. Today the books show a list of weights, 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 <= 5356; 0 <= a[i],k <= 1000000.

Example 1:

Input: 1596 1914445 916033 985157 679075 427060 826427 410384 289947 926351 551288 249649 402100 349377 959263 222372 767353 270545 376778 924106 634794 152712 334427 635223 153846 212325 808074 888299 766633 715933 209578 247116 751092 619787 677781 385863 481259 687277 780951 575859 966478 184313 230336 431069 72951 327303 527695 265496 58275 101908 587693 932676 979684 178926 393848 47814 385984 809928 401937 412585 382886 302065 412323 40649 167651 738729 390448 123810 977354 219206 38013 766992 603881 665447 395869 120154 503756 322791 875287 178673 125756 714557 673602 811387 255459 163463 693340 953632 969288 209992 429626 324996 142978 831505 539042 373936 763667 359292 935876 418440 376406 468212 758458 196752 501650 450642 528027 611042 558199 536864 405390 789891 431348 621331 939796 3…
Output: 1914444

Example 2:

Input: 5335 609256 413772 623361 253580 603395 500725 974439 63982 637501 429556 591671 284538 456947 613530 878493 199436 544053 22259 595743 476155 199966 452597 510808 37578 24070 627310 608218 656062 181029 836643 130924 366489 177468 252447 801842 197358 347451 101060 306495 62084 725589 387312 461946 411461 94386 751135 210809 568322 784933 935730 686099 610075 830681 113872 364439 561331 381849 143846 56892 868712 299689 267246 108469 669010 790810 617988 128168 794135 83295 54478 981195 992684 300155 749169 668644 971219 205083 265545 120389 980327 626161 755604 844564 182570 751640 937149 944427 359190 525521 916058 35174 956700 592406 745917 690961 308085 341945 7479 900304 793366 70666 224571 300781 851534 480581 237729 226191 453985 323405 270975 692995 983966 905 590287 164883 671999…
Output: 609256

Example 3:

Input: 4604 868908 867975 715814 618657 904919 305354 852493 287233 410192 208744 321441 344809 955668 871228 659013 912501 770472 33566 598071 962704 810709 687579 740162 987153 599090 595324 667714 381684 868235 728600 369062 621985 264013 322754 310437 359734 604606 514688 373645 948641 781278 365759 988909 837050 973254 63375 859774 622327 535106 340606 241364 800105 190090 141111 16594 77967 139660 377922 957181 812691 149101 502095 439254 713845 997692 262701 72634 933079 960161 751860 243594 498587 397514 128051 480974 434391 941831 589454 150312 752319 806072 150372 911830 763972 644635 623593 938339 476201 603328 433407 232245 608421 649160 800697 31059 966125 369156 141657 365930 203090 357705 389785 437001 591926 36666 469640 287768 137601 384225 291838 158203 741504 854822 772824 6793…
Output: 868908

Constraints:

2 <= n <= 5356; 0 <= a[i],k <= 1000000.

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