CT39151

Herald and the Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the lantern lake of Firefly Mere close for winter, Herald must finish the shelves 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 <= 3057; 0 <= a[i],k <= 1000000.

Example 1:

Input: 480 1786492 822124 931006 60282 389835 932216 824088 144929 406855 9231 911314 202262 490049 27685 954409 858899 342616 99133 552328 586870 141846 332421 862938 651475 565752 814640 515667 973377 814995 190787 107993 343433 381854 222228 81927 768156 302588 304188 898501 982524 494556 499028 190567 155388 777928 354359 223215 973370 952432 426979 149676 914742 640466 172337 446278 798319 307160 392815 707818 457080 477028 100457 338532 352656 68063 313474 274556 112858 18841 326327 769886 420588 738410 30797 119575 379462 566526 312757 106786 491439 825351 69363 572236 991918 127121 65004 872676 556049 82367 430156 118311 87481 906022 509832 694652 958680 295246 703809 19700 119008 613389 881345 999187 438227 138234 577725 337610 310824 553101 91224 790774 232721 99113 86616 400039 855039 …
Output: 1786543

Example 2:

Input: 590 442772 531321 465671 535536 170792 664118 282089 802184 825524 258049 756639 610218 154283 712302 823561 302269 525486 803714 303779 281046 106767 891183 643246 448608 769413 336755 729183 882472 278893 665866 656147 400024 86953 350997 315752 654328 46325 639905 624683 225000 681773 313934 691855 526224 490207 67756 740997 710469 767855 361007 673211 886010 357738 852031 756648 241225 960226 146835 109448 546638 983388 3397 40662 209709 672351 578588 742565 652898 50669 759358 196987 32620 449664 265762 236749 843697 99313 458788 230378 720892 517095 326358 221423 66139 264447 597757 100514 703747 593371 840011 27284 753174 298859 497241 275035 474743 58067 841783 108180 816144 440730 786563 757243 733339 534114 353748 756024 437261 265293 758881 278409 996822 684447 491078 451198 613…
Output: 442777

Example 3:

Input: 1928 1531195 782397 326624 388805 534635 226902 911237 334693 905456 293219 537399 942279 249540 935984 827964 203817 543180 156628 840183 712571 173568 526374 924730 998322 256077 720965 360322 773544 785778 369911 153687 779729 391085 4296 319818 885547 73077 58931 810275 238375 838231 736001 620229 459223 377306 514392 922240 552934 689818 177745 267744 480535 321808 62738 372223 556830 827267 602669 251402 532533 448749 759263 869543 739472 484286 699942 274893 695999 567490 11873 675681 440971 721998 217524 160039 437824 194640 864308 551117 180752 736445 618900 801068 444579 220322 814004 891873 368626 502763 818816 302671 751260 514772 946243 121176 404589 697266 31940 197383 570526 213668 195520 801777 890158 350499 489285 837304 826729 273442 49726 583595 8076 448562 370314 818831…
Output: 1531195

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Herald and the Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki