#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
int n, d;
cin>>n>>d;
vector<int>telefoni(n);
priority_queue<pair<int,int>, vector<pair<int, int> >, greater<pair<int,int> > >pq;
pq.push(make_pair(0, 0));
cin>>telefoni[0];
telefoni[0]=0;
for (int i=1; i<n; i++){
cin>>telefoni[i];
if (telefoni[i]==0) telefoni[i]=1;
else telefoni[i]=0;
while (!pq.empty()){
if (i-pq.top().second>d) pq.pop();
else{
telefoni[i]+=pq.top().first;
pq.push(make_pair(telefoni[i], i));
break;
}
}
}cout<<telefoni[n-1]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 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 |
43 ms |
1372 KB |
Output is correct |
9 |
Correct |
40 ms |
1368 KB |
Output is correct |
10 |
Correct |
45 ms |
1624 KB |
Output is correct |