CT39247

Hope and the Garnet ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the silver mines of Lodebarrow with crates of ledgers, and Hope the bookkeeper must account for every last one. 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 <= 2369; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 2048 -750199 -200054 -833412 -567766 841456 -161089 257405 -797118 -653088 628885 -400391 49458 -654416 732220 -166344 279550 275694 -53288 -647454 -805053 -391051 591844 -723752 313417 -285031 -77273 -498274 -560415 238906 543353 455733 808699 -201982 789112 919636 -75488 -190632 659013 982728 199544 528462 -979994 -557625 -168837 -377501 463463 -332288 -276148 -296873 -929164 -61645 -937110 867617 745121 408983 716987 -512515 -542029 -296617 135949 -171506 209191 730368 779178 -702068 201810 -127778 -562385 -464113 -555103 -541869 995752 -781148 -32820 -101182 682693 791257 511125 58020 943259 -433675 -573466 -340808 956310 73367 -470987 230095 -998808 528499 556982 494705 521162 361041 133316 -496559 -681031 250325 916659 231855 -207509 -266954 -15773 791516 726391 -716781 -358194 -2934…
Output: -750198

Example 2:

Input: 310 319500 -430012 715153 397647 -404435 53434 589682 -923080 871182 747674 932102 -896702 311611 -956240 600175 -421187 267199 619205 -707237 815421 701930 705528 -178697 -685612 146859 743936 75561 697306 -819400 -577121 -771690 690182 -908090 732528 -55880 107847 -649968 -64291 -856169 -953408 -583401 -199706 162411 545015 -436419 -197388 447009 22638 246404 -299868 475904 -368039 756786 -74701 -65305 442748 -308827 937152 -783775 945492 -949210 567578 -349530 -391728 -550054 108306 922229 -244319 277904 -790553 857792 995198 -354597 773162 266321 579786 -936367 -737662 -289686 -726377 -712763 -323651 -237074 963748 87650 104736 956479 -477150 602719 266205 66800 127745 -996548 619239 -761468 315691 -953103 76778 -339279 307097 -975115 638739 -769198 -444559 708211 935609 -39718 323340 …
Output: 319491

Example 3:

Input: 133 1067310 436176 -247635 919537 -945867 459174 -713427 229177 530150 -852650 -822311 62212 -596298 -741604 168812 -387893 -291718 -725735 755060 -653021 333922 -983642 -636866 766595 -314338 -368385 -480447 315686 -102586 -37918 899624 866273 -537909 712436 -332484 859129 -132286 31401 -772127 289848 22778 15578 -951543 -575910 -679522 305462 283886 -588981 703824 956026 608414 -581724 -647831 -149412 -406939 -56831 -162087 808113 100152 377298 -423544 724419 509936 -228450 -463307 762223 152708 -257966 -270086 -817870 -104117 6203 48173 -34540 -563609 -172755 912626 834420 -125594 585419 954964 -860436 -178849 -747778 154196 605580 15408 995424 999908 416450 -755791 -200856 528104 -784334 -517525 -771731 234598 -935551 281722 180510 -802296 289150 135949 317932 -930508 -381322 -323514 2…
Output: 1067120

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Hope and the Garnet ledgers - MEDIUM Coding Problem | CodeTikki