CT52979

The Faded ledgers of Scribe

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the river town of Willowford with crates of ledgers, and Scribe the factor must account for every last one. 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 <= 1491; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 1015 132454312 896913018 168126788 742935923 802488059 764630205 329115082 49642775 996086264 771654310 952141574 319271361 866618729 486334125 992947481 335042551 962702823 428923416 5997722 974287350 223585230 151190647 910159496 765693999 804978619 881658366 380132522 766600476 191029689 709865867 648176948 334111774 817806723 82710003 510458756 231910466 672134515 150775839 129267312 433174292 168630728 579625914 675843034 409810771 228522194 587553397 37208059 48185264 108872809 19798741 834588761 908414756 61773127 279832215 745119717 198532998 541088979 117244565 177424922 438681737 254945391 199845062 20589253 264613282 958011449 751727367 379060492 586963725 515503865 734607198 494399237 880573624 533264285 385993144 914805394 278995113 82129250 932856985 635035887 235842003 41613…
Output: 132465070

Example 2:

Input: 309 1734895913 902389582 708143173 184886536 177196472 949531169 205661671 354061832 663972185 584220886 986121117 788918719 722670673 36646939 357763373 475009566 581769318 193386777 480113025 882226707 248040731 832183863 443893027 197114605 386076984 153247999 219390945 827790320 959182859 316546151 75366037 205635743 534411291 26611695 292137933 46342221 833125602 857706397 285263422 361588256 62126994 302764859 932793405 823204324 899638933 6567675 692209301 70511980 716146469 644514458 404893467 985391456 158163523 424139119 68529667 530287523 185503923 634501301 315542131 260416055 941709046 913273143 268880420 599990905 229870135 57497855 773081765 172586998 404146647 790068242 21015871 822868513 940813266 871035089 18009610 943022154 206148252 221226916 887925243 291901056 7252252…
Output: 1734894407

Example 3:

Input: 286 1728302149 186118372 919260201 930472286 155991132 254411126 600744551 289742381 142822454 989422454 577610968 875351355 909761226 261056077 290210472 25815274 261188672 216366395 827872816 601081058 730216805 882915696 949665748 19289110 148866684 83684077 674317040 27433774 463743386 696615246 9064871 748129781 472601052 328599946 812332568 456704530 339535626 352842912 232044945 556302340 9966139 530798024 140117753 604310777 69360544 349248002 852071882 92335883 378245636 296611018 986769091 504479366 301839414 13912346 259343958 108138977 554722957 667533055 589893365 842410103 88706239 189820902 426552797 573821821 825215774 135048558 794658508 161307660 731841462 76954630 513851972 945113427 430928885 711357147 274714507 517562787 138970217 769135797 865027048 916620462 29182883…
Output: 1728302602

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The Faded ledgers of Scribe - MEDIUM Coding Problem | CodeTikki