CT50938

The Verdantstep Nearest Pair Sum

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The accountant Paige has been asked to tally the donation drive. On the desk lies a long table of ledgers readings. 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 <= 3596; -1000000000 <= a[i],k <= 1000000000.

Example 1:

Input: 729 -917572976 -497158927 207375605 398053220 128604925 789258049 -115626387 743131463 -564734082 36673491 727784335 -731710344 547714509 313749214 639273737 -571038687 120417960 -862846821 822384526 -855455598 -473951655 -396765187 -687028695 93752735 -565996809 34785741 -737073239 680217609 151650678 52197792 -763983553 743147419 93089986 163098098 601993754 645857752 8124299 874544890 -630713042 -983135646 731892884 -678354690 557677333 212772022 -740768508 153283147 758866194 -153642785 893772668 -56120973 314976199 -220428625 -320711359 666479422 -361064375 436330337 567210816 -356610614 -885858158 543237752 472126732 627430662 -707956912 230750621 754601172 140703326 333789131 -245970970 -707837209 -11725809 -245201780 -360758547 133213457 -190007722 -64987198 -966448727 -38457358 22…
Output: -917587606

Example 2:

Input: 3157 -887317974 -127902612 -427419126 695186518 982635533 974309740 66710117 750175302 -869515392 -110509829 -427876894 -342433618 -151073176 906529170 -162341951 643228762 492638753 130170904 117728936 448152931 -699044246 -820681720 749352661 817035020 -856427227 533130329 835681870 815581449 268848300 -26747197 258885006 179968100 -659566058 544146223 -306438310 -612541705 102578421 257815661 -939386715 359338178 -998468862 486825596 -872049263 -299883289 -720160505 -134895299 411203903 -578838882 -46159531 743698362 -794567075 911944412 442462209 890522046 746848917 -590432368 400613777 70989010 1531062 457292112 406569763 -49214118 -272797068 612800729 -641803130 47543453 -942594549 537448129 -509863057 -801568821 356892914 -917049483 488664720 644773 330618625 52863564 704052486 5777…
Output: -887318245

Example 3:

Input: 1384 877871729 -630036568 -782875488 -995097516 -880584300 204316356 -332767059 527847467 -462349881 881323283 304229212 -298783484 -113128615 317421014 312366283 -400837483 871632218 980503482 725287439 -381264090 73837066 483565082 751231073 839015712 293836329 -18716359 -77343603 -978038198 -367386177 252895354 -518618197 956329239 42090402 -248913726 25843949 94848177 926869182 808289306 -907880047 -441831671 -137269890 8133463 -181875382 -19398784 -807654289 -546085902 861670058 241128053 898739667 -464466760 -839806180 -817597877 365222315 833786899 -711077918 -621435767 976469361 -488682624 -811578300 818122620 962551989 168334174 -871574813 -188953119 904825171 437233805 193855564 -693774965 -75147314 -871924782 -495151533 366895444 470976949 -848516942 386791482 -982025246 -278212…
Output: 877872795

Constraints:

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

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