#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, d;
cin >> n >> d;
vector < int > a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
++d;
int suma = 0;
for (int i = 0; i < d; ++i) {
suma += a[i];
}
int ans = 0;
if (suma < 2 && a[0]) {
a[d - 1] = 1;
++ans;
++suma;
}
for (int i = d; i < n; ++i) {
suma += a[i] - a[i - d];
if (suma < 2 && a[i - d + 1]) {
a[i] = 1;
++suma;
++ans;
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
432 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
34 ms |
2140 KB |
Output is correct |
9 |
Correct |
34 ms |
2108 KB |
Output is correct |
10 |
Correct |
34 ms |
2136 KB |
Output is correct |