您的位置:首页 > Web前端

bzoj 4996: [Usaco2017 Feb]Why Did the Cow Cross the Road II

2017-09-02 01:41 513 查看
bzoj没有题面....

链接是到洛谷的

题目链接

维护有多少坏掉的路灯的前缀和

然后对于每个sum[i]-sum[i-k]取max就好

代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>

using namespace std;

int n,k,m;
int sum[100010];
bool f[100010];
int ans;

int main(){
scanf("%d%d%d",&n,&k,&m);
ans=m;
for(int i=0; i<m; i++){
int x;
scanf("%d",&x);
f[x]=true;
}
for(int i=1; i<=n; i++)sum[i]=sum[i-1]+f[i];
for(int i=k; i<=n; i++)ans=min(ans,sum[i]-sum[i-k]);
printf("%d\n",ans);

return 0;
}

bzoj没有题面....

链接是到洛谷的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: