CT46542

Urmila's weights Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the gristmill of Rye Hollow. Urmila spreads the weights records across the table and picks up a sharp pencil. 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 <= 1126; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 920 -456845 -800900 -930906 -113220 -522740 -508780 -63355 -526272 -497672 -21328 -755619 -417461 -235238 -751693 -836950 -539426 -629179 -68698 -135497 -430793 -900625 -383335 -936349 -993384 -123511 -705123 -13404 -264147 -522069 -58152 -40486 -978130 -552324 -339520 -511391 -940581 -753790 -438116 -388021 -189798 -361773 -383323 -754504 -503129 -444084 -580857 -97609 -564898 -694611 -352907 -234025 -314351 -642947 -582547 -18276 -640275 -632735 -397674 -163901 -839080 -270838 -191268 -625440 -92988 -987477 -264679 -370513 -18461 -849060 -918135 -583874 -952759 -732656 -784819 -512870 -679931 -779647 -507292 -190868 -512561 -437495 -999870 -671158 -668134 -715948 -150661 -261474 -967422 -28422 -582179 -620177 -651621 -293063 -110930 -61234 -226896 -11618 -808327 -155221 -626807 -471419 -…
Output: -456845

Example 2:

Input: 516 -755148 -106817 -230217 -127477 -175853 -172453 -31532 -79262 -508732 -445108 -552399 -765591 -315890 -635280 -700446 -754740 -433393 -142919 -557768 -418930 -217708 -426012 -87606 -279336 -811700 -487352 -81717 -762244 -65847 -569163 -930768 -48631 -936085 -843526 -307178 -812825 -596549 -343381 -569216 -475271 -509725 -604646 -796200 -87248 -505378 -734730 -151473 -644902 -652063 -942197 -414487 -633242 -904762 -40060 -388987 -925664 -880748 -335064 -355433 -632224 -155414 -6309 -175172 -203520 -951601 -699831 -969113 -85898 -718000 -983790 -645158 -958062 -332106 -323268 -879777 -817923 -182856 -911128 -624308 -764779 -773422 -552269 -770544 -291585 -551023 -541716 -169319 -616043 -149205 -260151 -648349 -89481 -465802 -574829 -595915 -908360 -685902 -742803 -120608 -268265 -430345 …
Output: -755146

Example 3:

Input: 707 -355802 -468258 -481001 -132599 -983556 -100938 -458505 -266892 -233778 -520041 -820167 -923599 -267796 -926567 -836439 -857628 -565529 -811966 -748098 -754205 -319827 -955436 -116312 -657426 -294091 -979057 -44660 -126678 -526706 -147858 -437337 -40345 -331331 -324106 -274227 -673924 -643880 -938275 -741600 -956054 -229121 -177930 -676545 -305662 -490906 -705513 -733481 -561734 -866726 -170531 -206186 -226437 -271643 -936018 -737082 -893726 -568237 -404671 -709315 -776857 -547626 -482004 -244561 -456904 -626936 -227795 -739057 -907644 -588762 -823580 -865673 -918047 -623928 -576217 -564288 -273530 -276720 -418432 -179308 -316212 -914815 -570626 -371284 -676861 -641505 -391926 -699798 -975339 -34119 -983108 -238935 -704108 -82868 -845436 -712333 -745069 -943304 -495469 -564784 -936163 …
Output: -355799

Constraints:

2 <= n <= 1126; -1000000 <= a[i],k <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
Urmila's weights Reckoning - MEDIUM Coding Problem | CodeTikki