CT48649

Eklavya's registers Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the coral atoll of Pearldeep. Eklavya spreads the registers records across the table and picks up a sharp pencil. 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 <= 1787; -1000000 <= a[i],k <= 1000000.

Example 1:

Input: 583 -661492 -550044 -73995 -612954 -685872 -472062 -604000 755968 -77765 35910 967917 -588356 -713551 112754 359618 -879166 -306053 -523976 340530 864088 149670 472420 192397 -295641 314292 -23851 869647 938450 543173 -815879 194508 889428 991150 -782340 704791 880105 480050 -514925 -22295 661701 766904 -385903 -556484 -230950 614732 335979 321312 855384 53466 -565503 -436507 970492 -702182 -89136 -248466 -442349 618035 -39890 -978310 -346737 984871 599523 -995056 -274067 -625273 738278 233376 -646168 -538858 -832785 834957 -164685 407037 130283 139776 827081 -702767 -791836 384430 -709593 -393216 502644 142200 -279655 -747334 892100 -528469 221172 -544409 -608167 -77662 505607 263841 12114 540784 -19272 342253 -160257 -529621 -900708 356456 943704 992907 928178 -739158 -897809 -621721 -62…
Output: -661483

Example 2:

Input: 837 1717094 -637012 -428111 705219 -741150 -248178 719020 649522 -601779 -559437 960458 369200 103891 -832542 -38238 -967059 529108 -571056 719484 -51143 32564 -944773 58328 -757355 -993413 128828 -322329 -362506 673882 140388 -245801 -694137 544204 516570 -500927 546975 -408502 232654 959478 -109694 715115 499400 -184965 807688 -77097 -256971 775114 92963 -273123 -740378 411936 132138 -549975 -991309 -50744 151973 308258 -886363 -957740 748693 -158994 292054 190312 -242899 -173912 -75601 240345 -380158 -731694 -69759 164115 370649 722575 730780 -185321 -668565 215918 -969666 -465042 -62198 -854805 95173 -322564 -124546 -11808 455361 -233251 283290 302625 -226388 938394 -160363 777054 -792067 583785 -181142 887707 -723464 -580045 -760278 -897199 823672 -972054 578291 52365 550519 -122457 -…
Output: 1717106

Example 3:

Input: 1762 1961172 -468016 222588 535570 -166168 689934 869270 -306693 314605 684295 145126 869968 -845431 -419504 -617384 102728 340161 99200 -779898 -418770 -171602 -433930 -57070 795407 252607 -852007 800454 313672 61900 948143 -320408 -948750 -369443 -133932 -540755 719883 -445097 -30489 768206 23054 118134 -798352 -535016 -386997 -171545 772209 803389 430827 -93085 196851 -541867 -358909 -810891 767956 683937 859298 -567772 297979 255318 -52091 97389 101472 -373645 -844441 273078 -326115 195651 -445978 -705396 426066 829095 80 495434 148278 981081 876029 -423036 -437304 -659061 698416 76791 -391990 -276785 -359430 836761 -805317 388993 -270271 507084 984463 -850290 138474 -389111 -783362 -943290 943008 -694588 -356442 550094 51295 616072 -202489 -271998 811437 51178 -195649 226926 132645 41…
Output: 1961144

Constraints:

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

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