#include <bits/stdc++.h>
using namespace std;
int n, d, a[300005], s[300005], res = 0;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> d;
for (int i = 1; i <= n; ++ i) {
cin >> a[i];
s[i] = s[i-1] + a[i];
}
for (int i = 1; i < n;) {
if (a[i] == 1) {
int mx = min(n, i + d);
if (s[mx] - s[i]) {
++ i;
} else {
++ res;
a[mx] = 1;
i = mx;
}
} else ++ i;
}
cout << res;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
25 ms |
3216 KB |
Output is correct |
9 |
Correct |
17 ms |
3148 KB |
Output is correct |
10 |
Correct |
17 ms |
3244 KB |
Output is correct |