题解
2023-08-26 13:19:31
发布于:广东
2阅读
0回复
0点赞
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
#define NMAX 2000005
int c[NMAX];
int num[NMAX+1];
bool all_recv(int k, int n) {
for (int i = 1; i <= n; i++) {
num[i] = 0;
}
for (int i = 0; i < k-1; i++) {
num[c[i]]++;
}
int total = 0;
for (int i = 1; i <= n; i++) {
total += num[i];
if (total >= i) {
return false;
}
}
return true;
}
int main() {
int n;
cin>>n;
for (int i = 0; i < n; i++) {
int d;
cin>>d;
assert(0 <= d && d < n);
c[i] = n - d;
}
int lo = 1;
int hi = n+1;
while (hi > lo + 1) {
int mid = (lo + hi) / 2;
if (all_recv(mid, n)) {
lo = mid;
} else {
hi = mid;
}
}
int ans = lo;
cout<<n - ans<<'\n';
}
时间,我是最快的
这里空空如也
有帮助,赞一个