CT54194

The vials at Briarthorn

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the forest village of Briarthorn, Lakshya the cartographer keeps careful count of the vials. Verify the safety inspections, every figure matters. 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 <= 2187; 0 <= a[i],k <= 1000000000.

Example 1:

Input: 1645 1248718462 439493835 441687741 258786852 174023929 91035247 123000256 670478390 892093549 560307757 770003822 49851451 625854542 130079396 66116989 964670485 509878746 957787529 795545677 42382171 853577806 384231029 526291038 372836410 973578627 114986723 97197282 944884688 875243590 423980371 163286001 594530381 590002513 55793418 260280790 143312968 893570513 385828409 24534393 240515744 172144997 895177839 599050543 538392697 734162278 970847490 607284609 505935420 185034504 84480469 591214111 584599076 138946633 829299622 876784213 772234988 85039352 563989857 485754932 369593361 546720528 564848285 364928296 126452003 773180665 732153245 993954841 626656429 982787905 838346981 849194300 936906794 18925678 621031300 341780054 395774650 41431207 84589086 778184629 91823675 9926207…
Output: 1248718449

Example 2:

Input: 564 908272133 868451883 529000775 249209260 168790604 536345895 165703749 776796004 249572652 641649367 234286019 921379685 739935990 24647332 672449867 249811710 45806271 800612290 399737527 534552004 977428678 681121000 447276994 795627919 241731310 904562893 153287609 970351642 766023463 502683987 595777055 843661785 355888539 411783590 887118039 376982758 427884310 158858868 106789894 682519987 965656149 535678796 37220296 995419762 662959133 782081159 335867827 114625922 427641800 736298711 38843648 956946795 430207938 318222434 131580230 525907247 92075039 491303486 538938358 970865039 268033495 226985598 188695753 89541660 832905280 579837691 111891714 704708429 901438105 300140181 773524449 861809103 347735409 251389554 769748146 253451334 746789006 96975332 535596213 15155647 7455…
Output: 908270122

Example 3:

Input: 342 1993756373 941199916 682405841 17505120 760825313 861801351 717234009 506464114 842573855 492867694 516129361 438852469 913401450 290518550 949619402 375620973 345712259 307257168 276675005 474678345 138392464 47022032 3190355 729151908 738213804 818983490 719018011 518553032 213147605 33708819 675704640 979971653 146287127 934128992 937692266 422268805 823716804 741912045 174010802 868546108 25621247 610766500 906881802 698613946 298714637 116208669 503095740 653102823 477970167 714954710 372686031 316727863 830844070 105675321 260412796 95162457 415777348 907460882 870552482 683539817 554084538 652419232 64157454 681818595 866562669 27841260 503606370 714876371 485692339 649546065 191360941 22032227 650655174 899255786 206372322 916904545 259002354 192038285 583509543 357364828 76451…
Output: 1986101907

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The vials at Briarthorn - MEDIUM Coding Problem | CodeTikki