#include <bits/stdc++.h>
using namespace std;
const int nx = 3e5+5;
int n, d, res, desk[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin >> n >> d;
for(int i=1;i<=n;i++) cin >> desk[i];
int i = 2, r = 1 + d;
while(r < n)
{
int best = -1;
// cout << "i : " << i << " r : " << r << '\n';
while(i <= n && i <= r)
{
if(desk[i])
best = i;
i++;
// cout << "i : " << i << '\n';
}
if(best == -1)
{
res++;
best = min(n, r);
// cout << "best : " << best << '\n';
}
r = best + d;
}
// cout << "i : " << i << " r : " << r << '\n';
cout << res ;
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |