#define N 200050
#define M 200050
#define maxn 205
#define MOD 1000000000000000007
#define mem(a) memset(a, 0, sizeof(a))
int k,len,m,n,pri[N],num;
set<pii> myset;
set<pii>::iterator it;
int main()
{
while(S(n)!=EOF)
{
S2(k,len);
S(m);
pii tp = mp(1,n);
myset.insert(tp);
int ans = -1;
num = (tp.second - tp.first + 2) / (len + 1);
bool flag = true;
FI(m){
scan_d(pri[i]);
if(flag){
it = myset.lower_bound(mp(pri[i],n + 1));
it --;
pii p = *it;
{
myset.erase(it);
num -= (p.second - p.first + 2) / (len + 1);
if(p.first <= pri[i] - 1){
pii tp = mp(p.first,pri[i] - 1);
num += (tp.second - tp.first + 2) / (len + 1);
myset.insert(tp);
}
if(pri[i] + 1 <= p.second){
pii tp = mp(pri[i] + 1,p.second);
num += (tp.second - tp.first + 2) / (len + 1);
myset.insert(tp);
}
if(num < k){
ans = i + 1;
flag = false;
}
}
}
}
printf("%d\n",ans);
}
return 0;
}
Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships 二分 stl应用
最新推荐文章于 2021-11-08 20:20:11 发布