CT54879

Last crates of Curator

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the saffron fields of Marigold Row, Curator the assayer keeps careful count of the crates. balance the workshop's books, every figure matters. 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 <= 3056; 0 <= a[i],k <= 1000000.

Example 1:

Input: 73 468550 69300 453007 830637 837624 964100 184284 659449 692926 652061 54448 978824 920276 533968 155373 778871 157140 520546 262754 312936 511300 275467 280203 72571 633390 687317 300810 167579 434279 976144 313638 374461 465595 985639 209812 305837 431650 228502 952083 391419 829002 225502 847990 599003 37951 376080 67998 738402 437510 370209 922142 939456 877936 810643 676651 799377 367998 428143 907779 505382 707471 809975 59487 852343 972012 534692 58476 533793 791319 397513 977124 952919 62546 723299
Output: 468389

Example 2:

Input: 2792 1692101 984643 86001 855853 592968 345584 706402 702832 744413 844817 581896 885065 129658 625597 522643 773519 989016 405524 949340 187362 92718 72431 522637 489841 143013 983998 912059 656843 743594 557408 468699 164501 257296 124800 419307 318075 217544 507902 85116 763552 315923 271588 887953 843206 687737 377505 566814 975006 979925 832668 670950 463906 736288 560675 70514 554818 858968 278088 440828 513722 693805 354872 777499 782290 149102 759542 185004 347785 984464 759657 603898 476630 183507 765438 25041 666143 961868 180936 486917 545306 598704 422225 264302 702105 452958 381494 691932 720700 855996 693376 550553 248243 854786 364604 61421 604763 258158 834921 556580 17290 472424 385942 507589 486797 657981 459548 599415 247140 348022 68250 638480 593147 911519 99894 793881…
Output: 1692101

Example 3:

Input: 2266 1518754 824052 14537 237042 192612 43216 891205 96838 269361 242137 549463 164637 564128 101540 332217 656215 873273 816927 528823 27898 792173 38953 966185 852908 936951 549999 747024 177823 302824 629216 831573 685153 676145 607000 882836 978812 733938 27268 438212 166031 205015 153364 145733 750117 886806 702298 556724 925118 490228 13673 604487 536082 57064 887774 574380 867558 109436 444951 444678 727873 401749 532156 30524 433370 270390 694674 865600 568087 501369 12154 901459 97488 401075 773875 462977 455789 955509 823662 740759 614 617412 942271 505432 496908 848007 324299 957783 871835 706712 572470 232841 512280 759465 952487 684617 550757 43553 959051 799432 207084 720594 539575 589130 499120 655080 311915 65038 448124 345392 724784 447964 758052 115619 594811 228070 53484…
Output: 1518752

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Last crates of Curator - MEDIUM Coding Problem | CodeTikki