#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
vector <int> nums(n);
for (int i = 0; i < n; i++)
cin >> nums[i];
vector <int> dp(n);
dp[0] = 0;
multiset <int> s;
s.insert(0);
for (int i = 1; i < n; i++) {
dp[i] = *s.begin();
if (nums[i] == 0)
dp[i]++;
s.insert(dp[i]);
if (i >= d)
s.erase(s.find(dp[i-d]));
}
cout << dp[n-1] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
504 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
46 ms |
3372 KB |
Output is correct |
9 |
Correct |
38 ms |
3156 KB |
Output is correct |
10 |
Correct |
46 ms |
3380 KB |
Output is correct |