Ranking sums

You are given n integer numbers. If you compute all the $\binom{n}{2}$
sums of any two of those numbers, and you sort them all, which is the
k-th of those sums?

For instance, if n = 3 and you are given the numbers 6, 6, and 4, you
can make three sums: 6 + 6 = 12, 6 + 4 = 10, and 6 + 4 = 10. Therefore,
the first of those sums is 10, the second is 10, and the third is 12.

Input

Input consists of several cases, each with k and n, followed by the n
numbers, all between 1 and 10⁸. Assume 2 ≤ n ≤ 4 ⋅ 10⁴ and
$1 \le k \le \binom{n}{2}$.

Output

For every case, print the k-th sum of all the pairs of numbers.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:12:33.233Z

© Jutge.org, 2006–2026.
https://jutge.org
