#include <bits/stdc++.h>
using namespace std;
#define int long long
int N, D, U;
vector<int> P;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> D;
for (int i = 1, B; i <= N; i++) {
cin >> B;
if (B) P.push_back(i);
}
for (int p = 1; p < N; ) {
auto it = upper_bound(P.begin(), P.end(), p + D);
if (it != P.begin()) {
--it;
if (*it > p) p = *it;
else U++, p += D;
} else U++, p += D;
}
cout << U << '\n';
}
Compilation message
telefoni.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
20 ms |
296 KB |
Output is correct |
9 |
Correct |
18 ms |
376 KB |
Output is correct |
10 |
Correct |
19 ms |
376 KB |
Output is correct |