#include #include #include #include #include #include #include using namespace std; typedef long long ll; int N, M; int a; vector v; bool ok(int idx){ multiset st; for(int i = 0; i < N-1; i++){ if(i == idx) continue; st.insert(v[i]); } int cnt = 0; while(true){ auto p = st.end(); p--; int m = *p; st.erase(p); auto ptr = st.upper_bound(a+v[idx]-m); if(ptr == st.end()) break; cnt++; st.erase(ptr); if(st.empty()){ break; } } return cnt < M; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> M; cin >> a; for(int i = 0; i < N-1; i++){ int b; cin >> b; v.push_back(b); } sort(v.begin(), v.end()); if(N == 2){ cout << v[0] << endl; return 0; } if(ok(0)){ cout << v[0] << endl; return 0; } if(!ok(N-2)){ cout << -1 << endl; return 0; } int l = 0, r = N-2; while(r-l > 1){ int c = (l+r)/2; if(ok(c)) r = c; else l = c; } cout << v[r] << endl; }