#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define loop(i,a,b) for(int i=a;i pii; typedef vector vi; typedef vector vvi; typedef vector vp; typedef vector vvp; typedef vector vs; typedef vector vd; typedef tuple tp; typedef vector vt; typedef vector vvd; typedef pair pip; typedef vectorvip; const double PI=acos(-1); const double EPS=1e-7; const int inf=1e8; const ll INF=1e16; int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; int main(){ int n,m; cin>>n>>m; int a;cin>>a; n--; vi in(n); rep(i,n)cin>>in[i]; sort(all(in),[](int a,int b){ return a>b; }); int l=-1,r=n; while(r-l>1){ int h=(l+r)/2; if(h<0){ r=-1; break; } int sum=a+in[h]; int L=0,R=2*(m-1)-1; if(h<=R)R++; bool H=true; rep(i,m-1){ if(h==L)L++; if(h==R)R--; if(sum>in[R]+in[L])H=false; R--;L++; } if(H)r=h; else l=h; } if(r==-1)cout<<-1<