您的位置:首页 > Web前端

CodeForces 363B Fence

2015-07-03 20:39 351 查看

Fence

Time Limit: 1000ms
Memory Limit: 262144KB
This problem will be judged on CodeForces. Original ID: 363B
64-bit integer IO format: %I64d Java class name: (Any)

There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights.

#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n,k,sum[maxn];
int main(){
while(~scanf("%d %d",&n,&k)){
int theMin = INT_MAX,idx = -1;
for(int i = 1; i <= n; ++i){
scanf("%d",sum+i);
sum[i] += sum[i-1];
if(i >= k && sum[i] - sum[i-k] < theMin){
theMin = sum[i] - sum[i-k];
idx = i - k + 1;
}
}
printf("%d\n",idx);
}
return 0;
}


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