CT39729

Surveyor's crates Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the temple city of Sunspire. Surveyor spreads the crates 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 <= 1554; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 645 1869837868 234434427 798146910 496054653 703407059 759470662 604888844 613577401 132964836 883760840 530587044 572443412 66658400 39561158 527978360 325523543 254535335 812687826 37999299 537126342 78659666 374142216 639976778 135048413 571463660 941444606 214818334 501405631 919901804 728096392 505798581 926115204 791611205 638656942 835173776 991243093 458005362 18594405 779662988 792294201 228645537 599493758 207737264 219831656 358443104 180114620 629249708 349284979 936929869 765321023 283510331 998554776 619188882 903679797 718640274 593846834 589148210 458985363 872149710 888595673 790140334 675611994 231115304 852994746 43897611 851922998 851355269 654660632 79439664 485162500 978106089 917943773 701184905 756437270 255307428 778402593 328022721 442728318 665076249 650790777 90…
Output: 1869938352

Example 2:

Input: 1530 1958791106 328619572 929238253 946326411 525051167 790602619 796768323 469089629 307551121 560460328 346077440 816115337 734463044 990884805 391856820 709026838 632714045 143964986 144198473 406885462 217082477 671044814 415275355 54555394 183032926 61028949 519533571 323194575 223254716 357684739 595478364 887681329 109655322 469225749 66107629 615822861 376387485 533125978 997943266 597588210 570725589 709546597 925856842 841735849 663072542 617605878 666962534 164713390 326926839 737446525 987867856 753742775 143896305 54245623 276219378 292070884 233760726 370973715 744856719 778632878 794311049 828157955 88915876 632703713 525931431 387323375 540896061 65155595 425725072 790270377 847478916 752846587 357181189 782196979 730814680 931677095 482079702 388540691 60341997 629004483 6…
Output: 1958778212

Example 3:

Input: 827 1337344056 945505321 768371805 727356493 477321693 885817498 779092926 665143703 457304270 111990331 131732158 104327496 254348424 123898727 662182291 529601564 716048521 423291646 366921871 638880222 682751216 886984847 968930827 164835385 370457807 693843966 511315299 393583869 418190404 525469088 985023121 403569881 229654163 88889255 937918383 41832706 440518659 110027886 656677794 914892576 961878257 164559518 183626803 950215844 462959012 200932392 459001783 752445782 334577684 595449732 613668216 799854609 250765874 573697670 782802663 186757892 927676804 861234776 39279207 206888943 964634584 647942973 832160876 494279932 389863975 848384222 174060527 363789206 306497642 760544510 74137939 370767215 903205301 186463393 524277434 159771955 879313261 85017958 668080832 249023121 …
Output: 1337348088

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Surveyor's crates Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki