标签:for 有一个 using 贪心 while 题解 codeforce last force
#include <bits/stdc++.h>
using namespace std;
int a[1100];
main()
{
int n,r;
cin>>n>>r;
for(int i=1;i<=n;i++)
cin>>a[i];
int last=0;
int ans=0;
while(last<n)
{
int pos=0;
for(int i=n;i>max(0,last-(r-1));i--)
if(a[i]&&i-r<=last)
{
pos=i;
break;
}
if(!pos)
{
cout<<"-1";
return 0;
}
ans++;
last=pos+r-1;
}
cout<<ans;
}
标签:for 有一个 using 贪心 while 题解 codeforce last force
原文地址:https://www.cnblogs.com/baccano-acmer/p/9782677.html