CT39818

The Crimson vials of Orin

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The reckoner Orin has been asked to prepare the winter inventory. On the desk lies a long table of vials readings. 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 <= 3395; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 213 386448306 221274289 651475659 198079110 842855164 -626512467 538631229 -694534298 -388312695 151837188 131752726 816486327 95091267 316091542 -236304841 668428943 366010650 898855451 -922670189 -854213562 -649070212 465275754 -728173890 -980629658 857053434 725163791 462185442 -122108475 -789230570 -230591918 859374885 885393598 210989572 370336891 -597758456 -666287872 195377667 752371479 -129073263 -294248146 408783170 309412530 742883645 -385867629 -737254229 31206385 -182163078 -218301630 -126616650 -637646118 -93397298 717340588 107538845 -705226573 187367722 -266334482 -654842359 556465651 269193348 -180708728 -417727975 -323887176 -390466849 715799374 408386498 -946965527 593294657 -657981430 -982597408 -661389603 -729039673 95896607 -85922980 955696013 -388887138 -930978118 716…
Output: 386574671

Example 2:

Input: 3374 859518040 131707493 112036709 -122667008 325132881 -45702326 304327505 33186971 640917998 323203550 -583472093 173239035 792632756 158033747 248166130 -169953836 -35391259 307048053 -905988683 -726981316 745623401 -258934514 815466101 499100548 -826068684 905800770 292968447 168346322 -477859561 -20470444 -599274387 356520054 800811555 608257040 -854358198 990313861 227157829 479907858 406718110 443850912 740638703 630278078 -150416369 489304911 -493621638 215227172 306703809 591378265 -461177667 -847148681 988568003 -38923005 191402601 -468446404 -744621186 80859521 72467219 454215346 -187050413 197994817 -661034411 874368855 215168922 822663194 958537058 788260384 -166011115 535024437 200712684 636926415 788053733 161538746 -9837796 507274894 810425127 -340532761 233560517 -18172633…
Output: 859517803

Example 3:

Input: 702 182257425 -762589362 -136050524 477520937 798769898 -869753889 -302427519 -68204562 -355291827 -744366504 -211853671 350779159 853978695 749852291 -528612585 -191607130 -575443296 -112176452 963599806 -707363144 879578289 -989840112 798112276 387165124 -51381072 -846470587 -685487241 -699187842 -614235411 -389185704 -586296667 10417335 196580814 144507647 5441830 959612080 697279074 532747429 4339315 472631402 756832384 938057440 -726553478 -532088287 644058892 949741544 -347081292 -902416462 785731985 529873735 -926929108 -155368857 919311821 547240606 -415501805 27306193 -628980862 631338294 -615754646 243413793 -151099397 560168162 11281468 -365779029 926155246 -662786507 751324049 -84818725 -947331291 -497290363 658000489 530333978 499723933 -50906554 827676091 -664421056 -46949798…
Output: 182256878

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Crimson vials of Orin - MEDIUM Coding Problem | CodeTikki