CT47542

The Pearl ledgers of Sable

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Sable found an old ledger of ledgers in the kitchen attic at the cotton rows of Whitewick. The margin notes pose a precise question. 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 <= 1008; 0 <= a[i],k <= 1000000.

Example 1:

Input: 157 1968355 282240 338815 984081 791261 334475 390090 402944 229204 504352 986197 65350 931034 251232 594567 573724 269469 956098 838077 708158 257345 108899 290504 643904 807782 941628 176241 603428 306948 863779 630929 964136 852644 247212 298643 427504 382623 451064 482518 99735 587618 315259 864817 944025 97304 257661 479511 882021 964385 553148 175467 298263 238908 373232 241384 656218 235819 314320 586946 54840 583033 704104 860440 257232 359919 626683 817394 553257 906117 778275 238820 440786 803384 91230 934747 383707 637570 452199 406684 874996 960841 672175 707647 689409 533244 892413 710001 671365 808931 786624 296155 454575 246924 34769 309662 366006 714272 3727 951569 257872 436483 511140 24040 59165 402467 987762 160146 478721 163360 334704 221425 654676 701837 378689 514549 …
Output: 1970278

Example 2:

Input: 36 746733 492585 597327 419455 744346 133496 783352 381614 604309 306438 993725 342616 579080 696795 969241 648509 857946 188231 238404 20365 874597 837395 389929 670428 946570 729672 394899 7811 383188 245724 788856 645392 210535 150590 995157 64495 753477
Output: 747917

Example 3:

Input: 761 57765 461981 113811 669086 176296 175004 54280 725749 90363 799782 502320 647758 649080 262714 202938 643746 570359 784998 477778 11695 403488 439536 949541 867774 135183 857976 488245 279710 296017 170976 936824 77396 635362 602580 788329 248567 837654 257394 383730 659689 433921 837088 414149 96794 513564 867321 771989 31860 937443 75412 53954 606590 358420 535421 28451 680913 177392 493042 928490 616141 6027 629087 59615 752202 537487 790471 337120 468367 301725 253614 860415 72313 276813 734472 501668 237153 85618 449721 410354 638036 642655 171817 667316 715910 391627 154775 137977 873527 64922 407656 853004 759417 660363 132378 409848 633501 369532 375633 21367 19938 227441 677529 525846 335190 44041 78407 620898 480253 799372 196910 286585 575945 966063 916578 57365 951790 15943…
Output: 57817

Constraints:

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

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