#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; int N, M; int a[100001]; int f(int x) { multiset y; FOR(i, 1, N)if (i != x) { y.insert(a[i]); } int me = a[x] + a[0], ra = 1; while (sz(y) > 1) { auto p = --y.end(); int u = *p; y.erase(p); auto q = y.lower_bound(me - u + 1); if (q == y.end()) { break; } else { ra++; y.erase(q); if (ra > M)return 0; } } return 1; } int main(){ ios::sync_with_stdio(false); cin.tie(0); while (cin >> N >> M) { rep(i, N)cin >> a[i]; sort(a + 1, a + N); if (!f(N - 1)) { cout << -1 << endl; continue; } else { int ok = N - 1, ng = 0, mid; while (ok - ng > 1) { mid = (ok + ng) / 2; (f(mid) ? ok : ng) = mid; } cout << a[ok] << endl; } } }