CT39451

The Amber ledgers of Ulric

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the gull cliffs of Screech Point; Ulric weighs the day's ledgers manifests and starts the calculations. 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 <= 2362; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 298 -874558 -108270 -954005 -712442 -958686 -993202 -219045 -613980 -252551 -120231 -924926 -737080 -568412 -684316 -905109 -46609 -212613 -173742 -252990 -247930 -598006 -886699 -174054 -812108 -498631 -8278 -796378 -47394 -125232 -87568 -432921 -687667 -35044 -544305 -444765 -201445 -195779 -194671 -901526 -388797 -757290 -148492 -86969 -38522 -364275 -23414 -363419 -218125 -663410 -6814 -504613 -607628 -322638 -633622 -681131 -265624 -156325 -329494 -353200 -746480 -842344 -529634 -554923 -490436 -812765 -101537 -953112 -917540 -224736 -671238 -999819 -693936 -60095 -998043 -256105 -803784 -652715 -725779 -584406 -446059 -702386 -822236 -478559 -954227 -257639 -50029 -256578 -37712 -833800 -251967 -493985 -119426 -879111 -399367 -595711 -366899 -89580 -372748 -684828 -847914 -534110 -85…
Output: -874572

Example 2:

Input: 2082 -604551 -974510 -88252 -360799 -315033 -132088 -461354 -207975 -477113 -577162 -437636 -995578 -44216 -936525 -336260 -136651 -262616 -918756 -1005 -933857 -604497 -907494 -82917 -851463 -896156 -286264 -613046 -45127 -760377 -861757 -374342 -811444 -860455 -573781 -672823 -110966 -638947 -427335 -364934 -428480 -975755 -603716 -346151 -372306 -583993 -273624 -786607 -549739 -262861 -375409 -202783 -162231 -708262 -115449 -583456 -272347 -835215 -656737 -18023 -365690 -325665 -753914 -297122 -248912 -956828 -447860 -776952 -595720 -251505 -204690 -990994 -815520 -962092 -390851 -924071 -921020 -109284 -725986 -549480 -526314 -809822 -673605 -413586 -501371 -608986 -9790 -653873 -176017 -997855 -742338 -613215 -325998 -269376 -185812 -799402 -104540 -24460 -997336 -759087 -133613 -2656…
Output: -604551

Example 3:

Input: 2213 -950445 -242755 -127157 -262004 -1712 -542617 -454011 -795015 -552432 -917885 -152256 -689460 -521539 -212879 -222155 -571121 -641231 -518417 -592502 -219348 -235431 -305074 -136900 -248000 -810721 -811788 -195631 -769812 -433813 -228502 -666465 -503733 -81761 -177228 -64434 -949360 -923850 -193367 -895489 -876749 -578990 -242 -94232 -764332 -601648 -855138 -908076 -423633 -687855 -137243 -825948 -910258 -282701 -902971 -550837 -825504 -416991 -398865 -115832 -493299 -647125 -907358 -459231 -472521 -662205 -510566 -425918 -396925 -653019 -194409 -329569 -791043 -803968 -426222 -777741 -833274 -155543 -602082 -325714 -807050 -751428 -822399 -768965 -355246 -92467 -702682 -150868 -831777 -742333 -109690 -853798 -267567 -511579 -56365 -89647 -438812 -729861 -451845 -813154 -900636 -17666…
Output: -950445

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Amber ledgers of Ulric - MEDIUM Coding Problem | CodeTikki