CT51430

Kabir's ledgers Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the garden city of Petalbrook close for winter, Kabir must finish the ledgers ledger - one figure at a time. 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 <= 1229; 0 <= a[i],k <= 1000000.

Example 1:

Input: 963 1063757 625826 361807 196776 555050 162548 645072 221578 133802 696358 329664 15965 290258 149051 758484 144695 781239 234936 727700 518906 230897 813433 982416 674956 823624 75239 875085 373397 696541 175995 373868 614859 105419 460781 455163 359565 751544 884189 662454 930549 606518 638772 883252 902448 143757 521181 486123 12887 929325 478252 511056 473587 536462 554079 447052 679450 250959 352822 120633 779073 111130 111241 500561 998147 444396 555085 889078 270079 397081 183517 271050 976993 278088 845120 795903 874651 651827 673843 78294 189935 647957 286345 946871 300190 491989 781056 193930 504878 627425 526811 518970 758029 972665 896815 869723 923012 142899 845493 247182 931920 879282 46401 440942 40965 365560 19604 329901 700405 217883 887442 508663 178398 237281 172276 1138…
Output: 1063757

Example 2:

Input: 767 189854 492588 887945 653296 109823 881153 800564 774550 304162 414495 187566 18868 758585 138220 549544 20285 204610 446907 712999 732917 634437 742932 28194 166564 61371 872595 103698 155906 594890 672367 829683 809456 109571 291086 909593 528782 483936 84592 549079 586426 203515 171393 55941 252644 191009 556211 328918 37592 5249 927969 70064 921072 921428 133607 108415 489065 298341 251758 139856 984665 180587 41145 656036 928874 409946 326676 857401 100067 186896 569834 53430 481654 603334 300757 304159 675965 340834 129532 824953 375899 218842 889263 661585 575444 249450 441315 247706 978223 846006 187157 771297 601853 218295 779930 41295 622970 491221 42357 882939 969139 329168 885498 127206 167628 239267 500510 711063 730221 246227 864924 651253 3634 460875 504565 761245 864036 …
Output: 189854

Example 3:

Input: 751 1738484 650937 139689 998730 219515 243191 670310 826362 170657 164714 992931 964507 107639 992574 291606 20196 560937 384560 749455 849470 526372 85797 320028 783245 867912 290797 203490 775229 304377 979098 203876 236665 192203 956299 979865 773747 931312 806030 399876 398374 645351 514115 698646 90264 181417 873314 279236 889309 926447 573780 983107 227675 920400 589231 946437 108798 499755 17834 690484 375937 553548 490579 904776 532611 739655 400571 341191 503808 451367 969680 725321 142301 93079 861605 392348 18929 26378 818144 513554 660794 258019 144925 259236 50611 540728 534900 592350 235602 305620 162352 657805 389277 611996 679636 506178 800076 808573 634412 865878 292610 689818 135601 893070 654717 314312 509434 627046 695846 40809 42871 454150 917217 673791 493980 619436 …
Output: 1738472

Constraints:

2 <= n <= 1229; 0 <= a[i],k <= 1000000.

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