import std.algorithm; import std.array; import std.conv; import std.math; import std.range; import std.stdio; import std.string; import std.typecons; int readint() { return readln.chomp.to!int; } int[] readints() { return readln.split.map!(to!int).array; } bool can(int myScore, int p, int m, int[] xs) { int lt = 0; int rt = cast(int) xs.length - 1; int n = 0; while (lt < rt) { if (lt == p) { lt++; continue; } if (rt == p) { rt--; continue; } while (lt < rt && xs[lt] + xs[rt] <= myScore) { lt++; } if (lt >= rt) break; n++; lt++; rt--; } return n < m; } int calc(int a0, int m, int[] xs) { xs.sort; int ans = int.max; int lo = 0; int hi = cast(int) xs.length - 1; while (lo <= hi) { int mid = (lo + hi) / 2; int myScore = a0 + xs[mid]; if (can(myScore, mid, m, xs)) { hi = mid - 1; ans = min(ans, mid); } else { lo = mid + 1; } } return ans == int.max ? -1 : xs[ans]; } void main() { auto nm = readints(); int n = nm[0], m = nm[1]; int a0 = readint(); int[] xs; for (int i = 0; i < n - 1; i++) { xs ~= readint(); } writeln(calc(a0, m, xs)); }