CT49283

Manav's Misty Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the pine barrens of Needlepoint as Manav unrolls the day's manifest of registers. 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 <= 1142; -1000000000 <= a[i],k <= 1000000.

Example 1:

Input: 508 -37501855 -454969706 -148418791 -984150456 -807216989 -279992660 -463175135 -97034762 -768388762 -64698844 -341512222 -807048156 -931917581 -112832104 -859840721 -810247074 -471966786 -610585441 -584578099 -998868935 -15021537 -527078839 -761638381 -203416831 -415609609 -413483383 -718027943 -674959755 -614032802 -553378980 -380989000 -864193113 -310487958 -37047178 -99214265 -794788595 -785015110 -25769205 -76870427 -107936052 -486348510 -700817820 -163235070 -529075864 -408819449 -399475999 -489108713 -990236404 -522881346 -416178889 -253535521 -325679899 -428861071 -127726577 -579755663 -235223703 -948051898 -242221379 -97272086 -278320125 -679218224 -251998779 -727781297 -635835863 -920400114 -79115955 -257267541 -945013875 -426196647 -509009030 -32953152 -732010 -10255260 -1850334…
Output: -37390905

Example 2:

Input: 338 -741132186 -564702833 -800328914 -471019848 -457795159 -623756249 -943301201 -621121475 -106841106 -513235835 -687603267 -820965229 -471909242 -818735478 -957111436 -818687995 -575512037 -962558396 -719515723 -252046444 -725389859 -726318945 -613203298 -622578575 -55958732 -329932867 -379884838 -544531652 -626794930 -76430471 -271399314 -470450075 -597314316 -27233862 -905542014 -376334932 -527626482 -335007015 -121379158 -981054890 -57807494 -762793375 -27971529 -30804671 -855922510 -714032248 -545571465 -295446509 -288414870 -784734933 -893549879 -576537420 -318539279 -619561963 -915302976 -332645306 -585946013 -381798017 -193119310 -477073199 -244976578 -871585615 -682272054 -382354419 -938856375 -303463653 -195834198 -3337442 -495651085 -515827017 -965226545 -196680309 -302830568 -…
Output: -741129168

Example 3:

Input: 781 -467816692 -907038171 -948310238 -392313771 -730769899 -660120360 -983837114 -379851464 -27556135 -8393967 -898660466 -259758428 -880233331 -600804054 -37743840 -827832924 -578293703 -755541081 -510517721 -777188024 -131825100 -697040954 -763492301 -920812416 -840333388 -465541922 -580919582 -726202462 -286676666 -959791579 -357127111 -509474927 -630269508 -72940272 -82747779 -672022000 -417616094 -894938869 -577885621 -939813393 -676895113 -231838426 -349317412 -968921739 -734939221 -441677890 -22799220 -565559567 -932549652 -788980667 -427777753 -794362569 -397782214 -812429263 -139029912 -498429129 -172494001 -802807250 -380130338 -425098840 -211454847 -387167395 -322936464 -723984936 -50274443 -526003747 -445793201 -960397655 -803571277 -823542593 -37128051 -71772915 -661062440 -10…
Output: -467808178

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Manav's Misty Ledger - MEDIUM Coding Problem | CodeTikki