D. One-Dimensional Battle Ships

time limit per test

memory limit per test

input

output

n square cells (that is, on a 1 × n

k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a

After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit").

But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss".

Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated.

Input

nk and a (1 ≤ n, k, a ≤ 2·105) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the nk and a are such that you can put k ships of size a

m (1 ≤ m ≤ n) — the number of Bob's moves.

m distinct integers x1, x2, ..., xm, where xi is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n.

Output

1 to m in the order the were made. If the sought move doesn't exist, then print "-1".

Sample test(s)

input

11 3 3 5 4 8 6 1 11

output

3

input

5 1 3 2 1 5

output

-1

input

5 1 3 1 3

output

1


裸二分

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (200000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int n,k,a,m;
int x[MAXN],x2[MAXN];
bool check(int m)
{
For(i,m) x2[i]=x[i];
sort(x2+1,x2+1+m);

int l=1,tot=0;
For(i,m) {
int len=x2[i]-l+1;
tot+=len/(a+1);

l=x2[i]+1;
}
tot+=(n+1-l+1)/(a+1);

if (tot>=k) return 1;
return 0;
}
int main()
{
// freopen("D.in","r",stdin);
// freopen(".out","w",stdout);

cin>>n>>k>>a>>m;
For(i,m) scanf("%d",&x[i]);

int l=1,r=m,ans=INF;
while(l<=r)
{
int m=(r+l)/2;
if (check(m)) l=m+1;
else r=m-1,ans=min(ans,m);
}

if (ans==INF) ans=-1;

cout<<ans<<endl;

return 0;
}