#include #include #include #include int main() { int n, m; std::cin >> n >> m; std::vector a(n); for (int i = 0; i < n; i++) { std::cin >> a[i]; } std::sort(a.begin() + 1, a.end()); int ok = n; int ng = 0; while (ok - ng > 1) { int mid = (ok + ng) / 2; int j = n - 1; int cnt = 0; for (int i = 1; i < n; i++) { if (i == mid) { i++; continue; } if (j == mid) { j--; } if (i < j && a[i] + a[j] > a[0] + a[mid]) { j--; cnt++; } } if (cnt <= m - 1) { ok = mid; } else { ng = mid; } } if (ok == n) { std::cout << -1 << std::endl; } else { std::cout << a[ok] << std::endl; } }