CT55575

Jace Counts the shelves

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the boar woods of Tuskmore. Jace spreads the shelves 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 <= 1952; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 41 1027132356 345323826 919096227 650604896 103949696 119216365 808480239 549257335 722094410 802267666 130669764 136434693 381969878 442884259 744142252 5270083 626736668 326623991 790284964 665667660 2280034 713931038 372533386 253994921 498936293 642147024 690603282 305747854 559695255 229237217 568160177 810925266 486124974 103714482 347309799 261536740 89974165 336902479 493317756 292045749 713801448 573105234
Output: 1027505761

Example 2:

Input: 219 222244336 586242772 399714639 57012316 7698515 466028179 757864645 430486741 14937607 725039504 153790157 714978038 86180796 656780875 693250573 711737066 815546767 178025004 754780494 794318031 959429496 540963714 268862383 286537014 404452805 251434531 247684714 759394639 963165313 693517733 336939227 449589742 104325558 593777246 108634732 821819938 82888105 268049878 484156247 39139048 814562563 928727373 403365868 83992375 360204722 841571699 579086354 555359437 880663439 730737407 925507726 991668422 902466277 168521815 364955816 842437449 12830768 382293842 969127940 410393863 346591778 921571885 130775997 122334660 583717536 228578487 426513315 85424603 281984531 826123428 110927633 728484430 373689902 467655517 388938570 390487136 789776267 241596896 245257159 590555416 628748…
Output: 222123841

Example 3:

Input: 757 1410981873 878719112 506842992 918071627 617992003 566862846 150425718 181614636 760596364 479152907 461100813 847272430 672156792 553543741 437447386 683095085 55084629 298870771 83894808 512427926 311401595 791396246 567200990 822175289 487022650 736201347 402460881 117432729 26419517 162943181 553195521 122365438 878654051 337941392 556189948 933733082 758870244 962902980 552978267 877356414 877373169 496430126 510099775 767217092 346093086 929391233 275724431 627806136 174414419 529789942 523558302 868593836 716249305 191041118 226321495 635320165 143990915 14304406 399387 899225763 807125744 483059841 888596498 400691137 425682095 583958535 191157892 466912976 184537724 570633597 750582240 658837238 227103629 673239563 557180900 112856124 325593508 423309701 91536868 158564166 238…
Output: 1410984329

Constraints:

2 <= n <= 1952; 0 <= a[i],k <= 1000000000.

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