CT41270

Cressida and the Quiet vials

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Cressida runs the ferry office at the rook towers of Chessfield. Today the books show a list of vials, 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 <= 2302; 0 <= a[i],k <= 1000000.

Example 1:

Input: 1805 1189245 634633 715963 841366 43974 661280 671369 224526 322227 949259 396138 489063 701466 233916 839951 782268 817785 786491 848012 469637 154107 748603 710690 378629 122186 272885 869798 819828 865942 865187 58081 858125 848955 338957 856235 207190 596480 572797 933219 359902 956802 699734 349157 276139 811021 781518 134906 265941 601416 855495 775903 497774 692584 438680 729511 147804 734801 587774 838547 955812 987088 891491 994358 388146 850614 711148 848871 885804 932360 905778 179898 15075 404028 511630 107855 43256 461516 42479 845553 631016 248587 617283 545236 498002 182274 316292 781497 753752 855305 171804 282250 275421 39311 296134 446615 477914 102895 68506 438895 54079 216373 364222 998753 259268 591408 426392 209103 862299 394838 893627 619093 111742 68932 324348 59907…
Output: 1189245

Example 2:

Input: 1674 648135 270986 719566 226286 674044 729190 28446 829784 568894 34380 247431 451182 531816 307294 749995 578179 906635 770301 379701 863835 995823 303077 774403 254418 94418 541619 261994 955804 16884 14792 716261 636611 307610 697263 128836 203071 778115 817118 415256 947088 628716 492840 982246 739009 299873 179337 330968 414754 110157 523286 737137 821032 967146 678404 374433 282123 201134 970088 379986 471545 231737 609847 706628 988284 487060 680184 848144 232079 684686 347802 833847 858217 960928 252967 951129 840868 815155 928012 453247 747669 984763 8450 922769 770564 661532 421831 664819 237804 654037 52397 76978 800967 51728 352841 162297 903502 62652 291741 358269 414742 886804 800700 906420 610796 73887 79700 991455 184173 391684 539733 157288 551885 958003 186550 498391 549…
Output: 648135

Example 3:

Input: 923 1689266 662962 370426 260747 48125 999871 172481 386579 119906 263279 120003 885003 231534 32571 856126 675839 765936 588363 220674 946176 613125 267080 51526 117211 932089 869743 274294 313177 206329 135709 642444 414595 26139 431653 830288 346905 239198 552460 950540 191073 367907 382938 675816 223305 879387 852003 147710 592386 220274 332082 181295 526486 991627 528560 715974 234915 948776 789535 644590 269645 203773 386762 860917 475021 296683 679049 356870 685818 816001 430889 359317 456221 302402 789119 518399 391383 541886 249516 170199 801364 136658 495449 814267 329300 87895 591696 612559 565868 216225 255095 800135 219892 500667 141223 63722 883922 651583 155158 6572 882979 69667 970382 453754 276901 124240 744534 324002 824591 505298 658825 971165 635637 444235 356772 629762…
Output: 1689267

Constraints:

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

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