CT45572

Tara and the Wayward vials

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the beacon hill of Lantern Tor close for winter, Tara must finish the vials ledger - one figure at a time. 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 <= 3958; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 3094 -774829223 659591952 -641468738 72904150 144118635 -779486596 -801544084 -554407772 -324130474 436753137 558351175 822984346 945058811 -382668306 -653578028 -839844892 -768855184 101111458 -483533056 971866587 -704574085 -242739638 416251880 -473731721 285545845 181175165 421429195 635867193 188524752 -720791378 5043748 -211335325 718756225 760496236 445593304 907631639 67907090 -320253454 -132914591 -101836514 593582425 -276061301 219433185 703085598 356893664 104053100 605031155 885642328 99147998 196349402 187342828 -1353414 238378260 928785849 -486045362 -361868857 -8351468 47192796 -131805964 616389755 -496182903 63918512 544874909 813933213 260274668 -171930334 516516317 616082619 -393781231 372688913 424476561 203808819 -374330725 20760733 -242129556 -201260126 -702798538 77136…
Output: -774828963

Example 2:

Input: 696 441565789 -878346227 -966213025 -621447493 788474482 -407632469 -162392562 -907931705 918558912 -440583899 171479216 -783347492 -502275745 937292338 -813867047 289390586 -185099621 603465624 780032918 188831820 290951989 -811394150 110545335 967660632 539018721 -125619280 217434219 451613021 -858728875 -44527522 -122982813 303072962 371658418 -561792005 311417578 -474240262 -870690599 766228127 -738497758 621460796 -888280710 283903826 199640237 -78146494 -232804638 -924032575 643210355 628405692 -108289418 998210783 -810011078 -8964356 -656451114 743414146 -559083584 -525037362 949687481 26381055 618846570 -610345104 338598573 354706638 -314714552 222598463 -757933159 245904849 703205130 79712141 -659752580 -94295365 -444262295 536649173 719616205 -336419472 -221639973 -845613742 2086…
Output: 441567065

Example 3:

Input: 2923 1740849176 -876992224 253726064 -76746040 702170889 -181641178 410882505 -948066213 -792370545 -484531439 -540030700 -317604914 -997422635 108119291 23120015 -230049485 467771811 182400623 -377151442 166414605 535955053 -407621562 -732451037 76171056 414492934 -910882333 -120650643 -658684102 827386847 821445688 -386713889 723693500 -648884894 658725052 -47346806 -445914033 -499263499 -715979608 -57065619 -707305903 618873494 283800608 -853134024 562742817 349010941 81094128 -923294896 -856930401 836637116 435283528 668105784 771984686 -369698885 -459134630 527376785 750999465 -990027390 -775222833 -910763170 475583190 -556016880 411762228 -389629219 -728351522 -590948603 -913211578 -983369202 187705460 -35954272 629906540 977036846 -400113081 -8961830 886548342 249538764 134685670 -1…
Output: 1740848687

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Tara and the Wayward vials - MEDIUM Coding Problem | CodeTikki