CT39339

Corwin's Nearest Pair Sum Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Deep in the frontier camp of Duskwood, Corwin studies rows of vials entries. One clean number will settle the guild's oldest argument. 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 <= 1766; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 863 1398271194 937799343 306484250 463655043 223422315 11570874 440950622 126297170 656368185 742394620 769664804 81232060 647551821 360381991 913223651 543240883 2934063 5381318 33763291 290412917 318793320 367426748 777456281 151286592 38258542 580745141 457474523 218086682 160749631 222175475 226035520 399081354 43557394 308367714 974304700 27112832 734168589 123834641 439098652 810382106 613828422 896449191 605128922 158731675 354820144 188457978 951374797 567124690 477906179 481696633 958415096 423464730 906422014 385276544 246604703 251060324 152787331 893978481 218857847 790623114 16009397 160607487 376959323 470312434 165843081 424682236 678008090 715077868 342029495 768500531 303447037 250620615 141425196 341248305 286215469 489631071 27634240 956766008 958199647 552923868 2835481…
Output: 1398270630

Example 2:

Input: 1255 1662541283 317070281 22901838 181005028 161783973 368590291 445019594 79034382 258662610 52825973 335830692 945975829 752568873 793894078 227686874 848489445 501664021 175269952 474283928 490089696 249477569 835799997 55490620 508822276 804614551 988438377 102844813 447113514 308335639 207517705 844170681 932980522 884608792 905034333 621643585 34464454 295456020 670863408 745380167 615459375 369952486 169697867 733956426 138792500 90741908 131460526 566570182 18351056 463308275 248253764 900726679 989502775 697194212 412012053 526629942 772968710 754951410 350317645 647345212 272702174 871890341 75912284 707387397 46915316 170149533 461839548 57615976 586705111 678722606 418230478 287511335 700799110 34343942 61931506 279396849 671016192 424705837 748876892 973302806 910202257 397778…
Output: 1662541149

Example 3:

Input: 56 1380668156 731959980 914502124 450178294 24761465 439333343 36284074 597453668 397024303 181717371 741849693 498040992 727261919 161569420 758375672 729022901 665439733 567610304 346228125 368587257 510629061 623061342 506671108 655257099 319457250 781041967 24158479 336395531 939790326 67897020 433625013 922451837 45653765 212662487 507469111 549183692 183290369 75144252 702671134 403146638 493009286 295615698 257959809 980143896 331348845 571610213 990236215 187988003 270973462 749306465 517973651 429677534 23553255 489518794 48177838 626646458 435733489
Output: 1381437014

Constraints:

2 <= n <= 1766; 0 <= a[i],k <= 1000000000.

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