CT47942

Brass shelves Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Bhanu found an old ledger of shelves in the kitchen attic at the sulphur springs of Brimstone. 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 <= 1795; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 1632 344619019 150553288 325188719 766010518 371524755 425130344 803347380 397293637 351226310 48437613 250779611 578434751 830502001 741444326 758952710 660922249 942178454 128671248 317643306 223215605 141600457 718644092 700161587 557317918 586140633 159179412 330105698 321665030 23397822 128622152 543430359 107914227 648056636 966066910 581124686 369490214 681548051 664196021 661495798 532318820 964954201 764660618 570809171 115040653 869131521 456270777 353441709 925206678 437789698 383039470 789607844 489363622 274923735 259230110 350770996 392677568 451903906 606032767 930291332 174517001 312280744 123600271 912602184 978526173 26696275 259505696 912287600 217327504 551469856 971565342 415035991 323864019 196318016 558330367 967601740 201414047 19011748 591308388 11879270 809478865 …
Output: 344619024

Example 2:

Input: 1326 398687983 347376702 188879869 393769953 704144068 127827795 308506436 895022611 265089758 762087963 788303542 637051684 213793569 549452370 110055705 795075776 737013862 99445733 209431461 468582348 115200826 502031744 757097640 811216033 734891341 139830141 795419171 892295911 405146373 783895796 474437991 162460632 968647911 280141564 989394264 737506017 963295566 134168416 685653271 850980568 977211537 407168130 577897017 130185188 364950431 479380030 998359164 529683693 268987769 633867935 8929283 751500295 748585241 587037460 775126316 413184397 757346061 43080342 493311635 947782867 162033732 916954311 914888494 379936685 225027314 998933391 919024617 129458306 604531110 185578744 661222414 55700856 367486722 374207885 14659098 225422612 408351323 406198897 849479418 221939838 4…
Output: 398690044

Example 3:

Input: 244 1070849843 877854261 649917289 788838580 403362872 21630348 7046813 932671663 318936000 550909404 256481407 727196354 973367477 500500667 170274451 265350931 781619287 933974954 662358669 155430886 690035409 335656988 10281831 885892657 639840653 943643919 232637118 191086244 130205558 726968231 181932593 176842982 808792480 741312809 342206063 145360160 349796945 418509777 380031210 800316957 126495601 905349011 42642343 848316117 900460358 641498589 948455153 196102509 602633766 941105531 42818984 408386310 731348013 240072067 726604541 784849387 234968503 469890324 562162812 651919553 654288352 513783481 967195497 66988621 901925960 473130559 621881841 393877139 686198752 171299222 10264424 126617555 131265830 401562523 357660554 273570736 468888906 657972521 639283809 963039881 434…
Output: 1070850359

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Brass shelves Nearest Pair Sum - MEDIUM Coding Problem | CodeTikki