CT49046

Woven weights Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the poppy fields of Scarlet Plain opens only for a perfect tally of weights. Vesper 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 <= 3657; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 236 -756607919 -940804003 -345719757 278619688 -474092037 -737827477 -296017122 -138194880 191573707 302528175 220958955 124046988 -542783063 317040629 749904638 225185366 -358839434 815689355 57310354 -58530334 -320715360 360286485 102217867 -421880883 31217042 -978204071 -542181017 146826184 -202126599 833773683 898662062 827085565 17120950 -338011121 -694166454 363825618 274926207 954300258 -939138067 -235109732 -300164212 -525032632 556703279 -105771016 -516358296 66252020 535683812 -812763717 929259393 -913171706 -294165502 345317128 -229744400 -179624723 -396010630 -470526213 -948932713 809899299 -373991956 808508451 458162901 -47771525 702184514 -880250186 -358945432 -184004553 290152753 451554960 188145334 239117077 524196466 -750197964 -750294616 472125554 49415000 -643576797 -954…
Output: -756534464

Example 2:

Input: 2910 1441490605 -119249651 882477764 613262928 735356789 908077593 172306078 -570072226 -668582864 872356581 333273843 -52762425 999486921 582830278 336671310 912502895 -250872792 -527732389 389292202 481683427 82990710 -155100157 894424900 -36653074 -614327098 445113665 -678229213 -198320954 554229838 898625929 760080132 590869818 179744986 484432627 435112569 -371192553 -96168334 678963018 -994139669 507438056 109953587 -199334441 -126682081 153183690 -363735818 578855592 641721955 550500073 387497557 145844454 -300784646 -767573757 310530906 -656366554 -37666870 37781226 739003041 555377124 -742066079 -176220637 112817696 856481142 -785663438 -62223973 -747538336 -755999843 -421083427 122848598 -428827852 -27013939 222248058 -176495556 -508716265 238861124 97141377 -659687852 -23652304 …
Output: 1441491670

Example 3:

Input: 554 -325954920 936323860 -365166847 -961977343 15568342 327387134 275173547 203040752 -504256891 93002602 -445498034 -292180017 569661941 -297392399 907563406 101625137 500121168 281335566 -117061329 -128006121 80747129 408163986 -686250933 145813630 -986574257 -842555552 184785849 -865513592 -732894969 -399437274 792716675 -661117492 808864347 731798856 839841946 270570341 -783639799 407452149 308708358 440363141 -914805690 42496182 343254613 619525565 -109003582 -204728190 -767267722 -512280349 -649361293 242733447 -837153473 -8138373 -856938038 -500016351 -716443204 -649921118 975628711 909433931 -122717587 991997672 363235247 855356125 -391042316 -112421685 -420030301 -236195424 -935064806 -948426027 871040402 -416262311 446143605 650228654 252556879 730787498 -478246179 -355600401 -34…
Output: -325955014

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Woven weights Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki