标签:img while pac ack define class char lap pre
果然是道模拟。。。
一开始想线段树
看了一眼数据范围:“这tm不是前缀和吗”
然后水过
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #include<vector> #include<queue> #include<set> #include<map> #include<stack> #include<bitset> #define ll unsigned long long #define pi 3.14 #define eps 1e-9 #define inf 2147483233 #define m(a) memset(a,0,sizeof(a)) #define M(a) memset(a,127,sizeof(a)) #define REP(i,m,n) for(int i=1;i<=n;i++) #define DWN(i,n,m) for(int i=n;i>=1;i++) #define lowbit(x) x&(-x) using namespace std; int a[10010],n,m,ans[10010]; const int Size=1<<16; char buffer[Size],*head,*tail; inline char Getchar() { if(head==tail) { int l=fread(buffer,1,Size,stdin); tail=(head=buffer)+l; } if(head==tail) return -1; return *head++; } inline int read() { int x=0,f=1; char ch=Getchar(); while(!isdigit(ch)){if(ch==‘-‘)f=-1;ch=Getchar();} while(isdigit(ch)){x=10*x+ch-‘0‘;ch=Getchar();} return x*f; } inline void write(int x) { int num=0; char buf[15]; while(x)buf[++num]=(x%10)+‘0‘,x/=10; while(num)putchar(buf[num--]); putchar(‘\n‘); } int main() { n=read(),m=read(); for(int i=1;i<=n;i++) { a[i]=read(); a[i]+=a[i-1]; } memset(ans,0xcf,sizeof(ans)); int x; for(int i=1;i<=n;i++) { for(int l=1;l+i-1<=n;l++) { int r=l+i-1; ans[i]=max(ans[i],a[r]-a[l-1]); } } for(int i=n-1;i>=1;i--) ans[i]=max(ans[i],ans[i+1]); for(int i=1;i<=m;i++) { x=read(); printf("%d\n",ans[x]); } }
标签:img while pac ack define class char lap pre
原文地址:http://www.cnblogs.com/Kong-Ruo/p/7896034.html