FZU 2168 防守阵地 I(前n项和的前n项和)

这是一道很容易超时的题,我超了n次了,后来队友提示我才想到,bigsum ! ! ! !就是前n项和的前n项和

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int sum[],n;
int bigsum[];
int main()
{
int m;
while(~scanf("%d%d",&n,&m))
{
sum[] = bigsum[] = ;
for(int i = ;i <= n;i++)
{
int nu;
scanf("%d",&nu);
sum[i] = sum[i-] + nu;
bigsum[i] = bigsum[i-] + sum[i];
}
long long max = ,num = ;
for(int i = m;i <= n;i++)
{
num = ;
num = m * sum[i] - (bigsum[i-] - bigsum[i-m-]);
if(num > max)
max = num;
}
printf("%I64d\n",max);
}
return ;
}
上一篇:HP服务器设置iLO


下一篇:惠普hp服务器通过iLO接口远程安装操作系统