cf B. Fence

http://codeforces.com/contest/363/problem/B

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 500001
 5 using namespace std;
 6 const int inf=1<<30;
 7 
 8 int n,k;
 9 int a[maxn];
10 int min1;
11 int sum[maxn];
12 
13 int main()
14 {
15     while(scanf("%d%d",&n,&k)!=EOF)
16     {
17         min1=inf;
18         sum[0]=0;
19         for(int i=1; i<=n; i++)
20         {
21             scanf("%d",&a[i]);
22             sum[i]=sum[i-1]+a[i];
23         }
24         int c=1;
25         for(int i=1; i<=n; i++)
26         {
27             if(sum[i+k-1]-sum[i-1]<min1&&i+k-1<=n)
28             {
29                 c=i;
30                 min1=sum[i+k-1]-sum[i-1];
31             }
32         }
33         printf("%d\n",c);
34     }
35     return 0;
36 }
View Code

 

posted @ 2014-08-29 10:15  null1019  阅读(129)  评论(0编辑  收藏  举报