CT47651

The vials at Leatherwick

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the tannery row of Leatherwick as Chandler unrolls the day's manifest of vials. The tally will decide the next shipment. 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 <= 1376; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 315 141410444 444632644 338691223 661192509 900067513 211693286 265480495 771841442 893499513 597507734 41844852 268990560 672960243 831467678 513313793 795660233 651043754 829985280 214313740 261636665 105518316 803634608 757238447 585740569 514165156 103129898 709734847 197472765 514747054 771878928 414765559 735462624 455946436 518618154 742244580 382651351 927538966 365067827 651266661 532681185 205037626 122373340 512246348 582504319 706765204 258144290 571192322 229387157 589754208 278020179 759258570 854693495 730040606 297192953 688276125 301329800 611740502 919087514 888435773 22177312 933272806 770250986 316274002 807527262 296844249 403382170 639375126 702577742 440129179 948703091 342116609 923353341 713175217 46681007 100903620 331882295 750546604 73224482 242075761 550247953 …
Output: 141405162

Example 2:

Input: 200 1099106635 404603525 32937464 101667753 462966265 615680384 193618366 64888745 924940234 12411602 457806653 660567761 358399233 626831134 102848806 619094273 841901146 542199094 45345851 909079754 764911204 752159283 738336163 995111741 864898650 620963492 578311621 640863246 638798221 5006445 954282272 853005918 988413703 488049318 602803909 633217734 688593942 495699988 366865886 12727596 470394576 308008526 412725668 403882578 370475452 251191835 944433035 930745970 294260921 399757521 348745236 300392113 991528311 669175930 590985441 343916803 745556783 550814516 389046134 409571269 582565094 640243028 769730052 945135515 68990477 10867556 232251673 33598085 546336929 592160097 776518989 747591131 803836985 233769284 415484047 717482350 388042265 881087817 34726548 635669640 848636…
Output: 1099117420

Example 3:

Input: 101 1096487119 803613941 693446532 800187891 932310865 371074040 464616264 187986302 50751636 120593818 439824149 877073191 748333781 722239131 738132440 501642785 973213725 60070880 168216323 707558625 645907967 712095592 57040995 578316862 444201142 709253795 13150811 663203177 55722470 942749363 703521031 638380838 570713204 540089214 301608248 793528682 77526167 677498126 288657585 254776701 772324385 652782814 426548391 302079104 26792550 220874679 781962532 944774239 334500309 151878252 765179222 952933898 296133032 688575484 207304308 921069788 310066061 822178870 880541227 801079279 803275364 271248441 855989753 457687892 196548377 238950916 299035964 599269948 465759435 843855307 487233556 806782878 764142802 976217819 288693774 797020269 435500851 470440377 307261704 593746514 79…
Output: 1096652491

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The vials at Leatherwick - MEDIUM Coding Problem | CodeTikki