CT49304

Gardener's Twilight crates

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the orchard lands of Applerun opens only for a perfect tally of crates. Gardener means to find out. 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 <= 3391; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 2037 1729194812 267316818 699002929 258983898 850901714 221344893 400119843 345172672 815698185 888070150 229517118 594805903 285702966 7323114 813548378 421846003 376786969 981690318 655997598 143891808 333072537 1347523 11186843 483440091 826218050 427139439 835721693 871400953 165136785 180407192 372548934 724752204 610762473 197196102 897286637 21379773 371232968 644592458 231384567 448276827 831344850 100333424 158996630 238928403 619181337 841503535 210609035 335889122 634749742 574138964 474841112 643972644 227591864 993344960 254466730 987148104 525090132 216731102 70685190 728281734 528937373 656057374 700052617 932713521 971854380 317669436 981376187 875975084 152884025 933847917 515049795 463292507 297171798 201057435 877552562 140188656 986801697 381840594 93801128 754582576 67…
Output: 1729196531

Example 2:

Input: 616 1290780300 346538293 72151410 787648821 845184623 263617699 775800756 525866294 259072532 656690750 65755486 276693754 321330554 882604786 61054853 546232693 632994391 387382206 662132075 951952385 637578459 632237283 529030704 658163986 936389655 694585964 776880313 998003111 64345447 570415669 346236115 175618798 148853492 436264054 59576878 345026149 721958470 517615054 914547729 184246049 118044234 889723486 100060030 488288138 401318359 672080114 820711920 361172978 574387789 192913210 538240785 274756940 714388391 539857555 273440062 540392434 779374450 240563318 611463299 461089165 704291712 626865355 727879768 668549463 348931459 465068587 978518655 466170277 443306138 23881361 697712821 456149891 94545999 799881205 19957339 705694804 727833024 487831253 941987713 188080732 788…
Output: 1290785482

Example 3:

Input: 483 97957521 406444568 974755560 482268207 744898650 573689455 373638467 259778322 205613146 307714213 492123685 146757037 379928947 152521196 233682400 695823188 608203018 879450000 94041124 960558831 292601400 257218602 951956547 172414421 709957767 221129445 993814651 279672683 452029943 759709530 818195451 146250112 889255314 215057349 473044635 604645238 742592448 781744724 825100672 609863784 86647144 158426625 856103490 767593591 158708733 23295624 781837388 843278630 222834857 667664947 838292370 178148614 337041728 356348704 542787095 672419243 916770886 275260670 356346796 66815589 876969313 738397699 180049447 322377821 597541417 406125451 790449281 475767006 668733927 80363349 453623170 795169630 899073732 4942273 673525474 689545214 261529193 616538018 159762679 195342733 6856…
Output: 98068754

Constraints:

2 <= n <= 3391; -1000000 <= a[i],k <= 1000000000.

Loading...
Test Cases:No test cases
No test cases available.
Gardener's Twilight crates - MEDIUM Coding Problem | CodeTikki