Loj 514 模拟只会猜题意

原以为此题必有高论,结果直接 $O(n^2)$ 暴力预处理答案就可以了.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
int out=0,fh=1;
char jp=getchar();
while ((jp>'9'||jp<'0')&&jp!='-')
jp=getchar();
if (jp=='-')
fh=-1,jp=getchar();
while (jp>='0'&&jp<='9')
out=out*10+jp-'0',jp=getchar();
return out*fh;
}
const int inf=1e9;
const int MAXN=1e4+10;
int n,m,ans[MAXN],a[MAXN];
int main()
{
n=read(),m=read();
for(int i=1;i<=n;++i)
{
a[i]=read()+a[i-1];
ans[i]=-inf;
}
for(int i=1;i<=n;++i)
for(int j=i;j<=n;++j)
ans[j-i+1]=max(ans[j-i+1],a[j]-a[i-1]);
for(int i=n-1;i>=1;--i)
ans[i]=max(ans[i+1],ans[i]);
for(int i=1;i<=m;++i)
printf("%d\n",ans[read()]);
return 0;
}