CT47990

The Nearest Pair Sum of the Crimson ledgers

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Tanya inherited the counting house at the snowberry thicket of Winterholt along with its curious bookkeeping system for ledgers. Time to make sense of it. 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 <= 3345; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 3235 96150218 457730964 -888560798 -300700223 793380419 377897910 -746811015 105863554 -984301403 20234734 228625497 -465806740 643277047 451134756 -747364198 509257469 249452665 785544431 -571887650 302154535 242614499 791826337 -498497219 -35744551 -399476669 363233983 751567778 246772230 792938772 -541440489 -591198459 -174881052 342743817 421721819 495113961 -803158509 -669227259 509683860 779956014 -117582172 477743387 705402795 -893877 -669861930 -891088634 486234486 753091458 829265579 -823267503 -160435455 947058819 -892807621 -525714130 343747484 -106087302 -943063961 -147668241 680989325 -279154522 14923893 -38518694 -965795922 -146849630 -3158593 983152765 -689627375 -89969490 335230536 -993863130 831413026 201151622 7371595 -832180676 -615606943 540265299 -878432508 -179808525 …
Output: 96150005

Example 2:

Input: 842 -34576167 -872473670 -38761754 -135670027 273525413 727126706 254807715 824341381 -482338438 -769790774 -608260992 -684790399 -688950713 -395371712 -895446255 410977082 9352285 -795940194 -996381207 164125040 -225133828 690914284 482441461 495729551 -422736706 837800759 472955605 949925302 -264916387 -938272949 49072247 604150425 753614018 -126709651 -9343358 839602325 69215516 915224755 766261386 -225680572 -740040644 -62723298 -3682807 734595258 826224854 -105188813 667196833 955661988 930923882 -135497893 720882515 -96054543 209224208 318162519 358461746 -588355434 -753825893 -667078555 575768934 917978355 496666808 710648464 555384307 792646467 699129631 480612311 -294953326 959695564 -236258175 -892706007 -996155698 -111626687 -151666692 -62325652 -120530315 70454042 -245137494 32…
Output: -34573626

Example 3:

Input: 932 -155497243 -343487003 -831893665 -854697483 -676778873 -607511156 74780208 -290201855 221981633 -726122448 -153197032 -829994063 -973931642 -676207039 559682632 -599000228 564142303 -130029957 -650231195 131868908 -629839093 309562866 -279232099 144448818 -389255674 540523684 519996267 -354091942 543944308 -169271521 535434590 407002435 -265569303 -336846016 73215218 -545223059 837468092 -868569245 -873707622 -879165899 975787253 -750953227 725608756 -207212263 288176018 -466334754 -178079938 -187098733 521572034 -24620646 -908517119 272965565 926344366 -447396868 -98345523 758779573 -462252117 -952578447 -630163622 738495349 -58770888 -61035136 474453222 241364863 208808947 881046215 963947612 50977667 483680491 588988702 695255039 -910180539 467535052 -584393773 864236113 -805808149 …
Output: -155497735

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.