No.507 Game Tournament (Team Formation)
タグ : / 解いたユーザー数 116
作問者 :
nmnmnmnmnmnmnm
Problem Statement
At a game tournament with $N$ participants, it was decided, as a social activity, to form teams of $2$ people and compete by the total score of the $2$ people. $($By chance, the number of people is divisible by $2$, so no one is left over.$)$
Prizes are given to the teams placed within the top $M$.
If multiple teams are tied with the score of the $M$-th place, all of those teams also receive prizes.
$K$-kun has carefully researched the participants, so he knows how much score each of them can get.
Find the minimum score of a person he should team up with so that $K$-kun is guaranteed to receive a prize no matter how the remaining people form teams.
If he cannot receive a prize no matter who he teams up with, print $-1$.
Input
$N \ M$
$a_0$
$a_1$
$\dots$
$a_{N-1}$
Line $1$ contains $N$ and $M$, separated by a space.
Line $2$ and the following lines give the score each person can get.
$a_0$ represents the score of $K$-kun.
All inputs are integers.
$2 \le N \le 10^5$($N$ is even)
$1 \le M \le N/2$
$1 \le a_i \le 10^9$
Output
Print the minimum score of the person $K$-kun should team up with.
If he cannot receive a prize, print $-1$.
Sample
Sample 1
Input
8 2 6 1 1 2 4 4 4 4
Output
2
For example, if the teams are (6,2),(4,4),(4,4),(1,1), the totals from the top are 8 points, 8 points, 8 points, 2 points.
Since these tie with the 8 points of 2nd place, the teams down to 3rd place can receive prizes.
Sample 2
Input
6 1 1 1 4 5 1 4
Output
-1
Even if he teams up with the person with $5$ points, when the $2$ people with $4$ points team up, he loses because $1+5 \lt 4+4$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。