CT50521

Ashen ledgers Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the copper works of Verdigris close for winter, Asha must finish the ledgers 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 <= 3162; 0 <= a[i],k <= 1000.

Example 1:

Input: 2338 1465 659 96 914 600 951 72 238 645 661 735 462 621 715 344 304 196 437 831 730 238 864 828 223 970 573 44 586 137 824 362 93 254 451 944 692 522 824 120 236 827 312 3 531 138 268 833 260 240 661 677 655 484 77 344 565 730 650 361 142 306 402 397 976 665 572 775 707 949 365 501 483 358 218 844 252 721 71 531 185 19 980 205 98 379 172 38 801 862 234 112 928 890 932 22 789 273 832 148 991 372 658 327 922 249 118 350 59 74 552 712 884 256 737 250 578 262 793 184 699 272 668 89 272 280 430 468 687 946 58 237 292 497 155 838 521 221 639 913 740 806 958 978 594 43 817 188 158 891 187 53 257 951 420 330 623 138 964 924 731 484 238 99 926 47 622 502 214 998 23 523 667 492 683 524 510 68 988 636 473 920 585 653 629 773 295 45 47 367 958 832 689 283 790 836 287 552 164 699 895 413 643 941 968 63…
Output: 1465

Example 2:

Input: 1526 1755 892 395 191 31 21 575 60 169 743 595 282 422 969 481 573 165 804 151 740 570 403 465 258 254 916 293 264 76 503 9 814 565 1000 768 335 355 806 578 381 783 692 769 397 366 507 358 299 490 386 851 483 956 696 824 144 7 924 713 875 657 204 124 894 644 677 239 516 273 672 344 445 756 612 286 644 41 296 983 197 128 522 428 758 920 208 808 605 175 980 536 289 464 121 922 941 789 840 795 840 88 359 442 573 666 417 72 952 866 409 386 21 361 513 118 686 445 654 712 542 655 846 560 485 809 498 174 616 223 272 797 523 367 534 868 80 772 570 555 511 260 49 125 868 436 883 644 993 281 644 553 130 928 47 103 814 774 619 12 92 26 553 286 748 6 236 325 131 421 639 963 92 894 709 742 251 616 69 781 693 6 505 840 881 397 760 396 498 118 309 979 437 775 488 830 211 287 379 80 547 845 684 913 976 38…
Output: 1755

Example 3:

Input: 756 643 56 939 772 660 695 760 9 472 869 739 785 876 226 248 433 792 208 97 477 887 379 875 561 77 435 629 443 300 92 701 826 786 692 648 935 866 720 906 450 495 623 974 997 227 886 554 300 62 226 976 405 13 219 669 589 176 874 693 179 429 194 311 847 869 219 747 290 945 55 168 956 25 55 751 191 483 841 596 625 858 185 220 109 423 948 237 960 501 410 694 287 318 567 505 50 549 16 801 123 295 484 624 902 405 823 314 806 713 289 8 592 910 317 56 949 834 165 245 179 277 926 519 312 701 15 826 107 194 403 731 168 19 778 853 542 969 667 576 956 555 525 349 982 562 234 874 539 754 472 882 447 661 604 56 193 798 645 768 150 614 186 785 399 43 337 508 347 283 674 282 737 151 127 206 873 155 849 957 991 519 39 362 17 302 397 274 811 214 578 857 615 327 658 303 167 102 363 504 76 193 398 565 257 783…
Output: 643

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ashen ledgers Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki