#include<stdio.h> #include<string.h> int sum[1000005],s[1000005]; int main() { int n,m,i,x,max; while(scanf("%d%d",&n,&m)!=EOF) { max=0; memset(sum,0,sizeof(sum)); memset(s,0,sizeof(s)); sum[0]=s[0]=0; for(i=1;i<=n;i++) { scanf("%d",&x); sum[i]=sum[i-1]+x; s[i]=s[i-1]+sum[i]; } if(n<m) {printf("%d\n",s[n]);continue;} for(i=m;i<=n;i++) { int ans=m*sum[i]-s[i-1]+s[i-m-1]; if(ans>max) max=ans; } printf("%d\n",max); } return 0; }
原文地址:http://blog.csdn.net/u012346225/article/details/42127319