CT35947

Hope's Pale Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the smokehouses of Brineport opens only for a perfect tally of vials. Hope means to find out. 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 <= 3289; -1000000 <= a[i],k <= 1000.

Example 1:

Input: 2488 -784634 -889409 -665295 -121527 -510680 -472309 -552524 -823063 -194128 -732783 -976922 -617247 -42423 -112017 -252205 -670556 -52378 -27169 -694942 -810134 -412010 -354539 -622754 -368017 -282060 -456040 -530384 -646496 -958496 -184840 -761917 -261819 -938627 -677977 -830158 -127187 -931038 -562291 -688555 -391422 -24194 -78506 -292944 -873221 -109246 -213328 -754685 -772013 -197578 -550056 -810645 -528205 -450946 -113598 -930831 -19784 -786890 -236598 -447551 -117885 -502118 -428703 -619541 -766875 -568536 -664728 -909485 -502293 -259775 -972797 -289081 -979106 -564962 -779374 -996627 -280627 -897229 -107526 -170938 -858189 -444143 -23614 -183169 -105486 -195877 -377998 -634210 -995414 -599843 -102922 -480512 -461591 -804876 -805838 -928741 -956320 -301705 -850829 -806361 -703789 -5…
Output: -784634

Example 2:

Input: 2881 -777566 -738419 -117011 -618507 -737605 -675104 -938397 -922310 -648423 -982100 -702361 -538988 -550523 -248551 -800310 -892340 -407313 -544604 -676896 -564139 -3406 -458629 -426533 -360311 -821880 -862026 -954825 -564012 -682204 -622364 -853636 -36887 -100838 -653365 -262699 -438664 -351792 -551319 -191900 -874965 -130132 -519054 -653919 -505342 -397813 -673650 -624160 -258565 -307264 -986705 -523488 -365456 -849714 -855865 -275692 -389250 -993715 -499712 -488021 -714638 -92191 -3180 -410174 -914590 -944459 -624251 -994166 -978069 -496208 -355114 -618926 -276044 -295729 -346372 -663538 -751844 -74729 -734382 -604200 -254113 -927519 -82152 -443467 -940899 -247199 -622484 -574645 -726298 -223895 -290784 -525909 -468788 -603524 -513702 -691792 -874118 -667297 -736766 -121401 -668009 -19…
Output: -777566

Example 3:

Input: 1788 -409419 -773258 -891993 -376979 -40683 -33615 -218362 -401566 -958130 -351807 -916848 -544433 -608087 -509718 -440710 -328344 -36084 -633440 -261415 -741570 -996067 -3944 -369933 -190112 -973518 -614233 -533827 -167678 -762844 -931173 -437190 -245527 -551516 -60215 -157547 -695757 -225331 -707646 -209540 -934424 -66314 -546413 -312103 -790359 -292342 -556545 -549682 -834026 -856212 -696806 -144523 -588325 -473031 -624314 -878326 -103355 -329204 -495905 -427062 -554431 -20950 -805170 -447789 -841562 -316867 -712113 -540958 -440083 -107637 -41051 -709286 -953294 -942608 -781215 -280762 -789179 -208340 -86795 -692663 -664533 -410076 -332842 -355374 -799027 -739255 -274375 -791405 -907344 -465527 -438925 -702790 -53230 -303892 -336258 -641042 -557887 -399250 -858997 -848848 -301473 -34500…
Output: -409419

Constraints:

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

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