CT53981

Kabir's crates Reckoning

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Morning light hits the sulphur springs of Brimstone as Kabir unrolls the day's manifest of crates. The tally will decide the next shipment. 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 <= 3327; -1000000 <= a[i],k <= 1000000000.

Example 1:

Input: 1210 1830494001 566716144 686638864 420389453 503092608 718968967 525616241 161413595 532097362 34332804 532768264 651276982 905996355 18467918 666760334 611409641 412472526 226566757 515010364 141900400 424832060 860761070 270954505 776932411 750493909 700620279 589798874 912062596 76720749 911642294 117651864 875335734 728868019 931311247 675801122 685670425 592829447 545163008 982577124 268242728 808057641 352079560 151055094 825227774 259531123 375011406 738560023 614412464 320105630 293823709 506256870 278169907 33443600 300951365 262166772 632007858 79750970 493744623 202097659 339974058 579452878 301561944 967913858 198195385 979878336 255126041 567543874 273953579 503644554 601019315 167674515 135982761 1405053 791706431 899960875 822224803 883311285 375575438 409167780 739528545 3…
Output: 1830502021

Example 2:

Input: 3086 659331275 456888373 278120822 164475313 43191208 499332102 619336490 654682229 480983656 982741730 274062315 928796878 265064486 181450306 740945259 704032193 993164532 952556242 759646347 926564256 39618604 800011465 93064275 771831559 450535050 196565328 708450863 261375575 858104708 593394324 900474598 489091495 304493025 137804790 502766093 892854482 795257582 646514346 838338710 787836259 962206360 483004004 718879734 828751398 224165129 692306615 779383567 115219499 851377766 405571586 796173545 826347180 879038960 390353193 888751782 884695819 453860979 477415504 907553559 230588662 555245349 335016106 190443965 380112181 683972134 729025156 252592443 55284675 537335286 152693985 847731267 372917162 798191625 935377934 723754632 360903141 455705769 195269321 360677069 270994150…
Output: 659331717

Example 3:

Input: 2855 401959318 579452955 63369717 990215268 853870996 249085915 549447664 815896794 648901199 370097003 169812904 515280200 42234196 525089264 468026642 133864368 862190876 108128235 525643661 495952727 106832329 206473975 182787713 629228091 756547980 693354518 49884052 423316553 635787752 497128227 866813602 642766954 804777100 304123815 471145157 242392295 895550910 920899751 909054403 444759113 937145048 381433748 476866765 690060177 343908739 488526468 504796621 914478944 139363083 541989939 288689880 443422835 157264375 342131736 457575969 395286989 622150240 809632557 787725377 640932687 427173742 201581602 709727634 393445968 645868248 508869826 585361914 732445155 146936724 880673133 1840738 600818893 651639930 325237859 833799619 39903712 379752824 353429638 750260062 902023080 1…
Output: 401959436

Constraints:

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

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