比赛 |
防止颓废的小练习v0.3 |
评测结果 |
TTTTT |
题目名称 |
数字游戏 |
最终得分 |
0 |
用户昵称 |
Hzoi_chairman |
运行时间 |
5.006 s |
代码语言 |
C++ |
内存使用 |
1.08 MiB |
提交时间 |
2016-10-19 14:46:11 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<deque>
- using namespace std;
- int read()
- {
- int x,f=1;
- char ch;
- while(ch=getchar(),!isdigit(ch))if(ch=='-')f=-1;
- x=ch-48;
- while(ch=getchar(),isdigit(ch))x=x*10+ch-48;
- return x*f;
- }
- void write(int x)
- {
- int cnt=0;char ch[50];
- while(ch[++cnt]=x%10+48,x/=10);
- while(putchar(ch[cnt]),--cnt);
- putchar('\n');
- }
- int sum[201000];
- deque<int> q;
- void push(int x)
- {
- while(!q.empty()&&sum[x]>=sum[q.back()])q.pop_back();
- q.push_back(x);
- }
- int main()
- {
- freopen("ggame.in","r",stdin);
- freopen("ggame.out","w",stdout);
- int n=read(),l=read(),r=read(),ans=-0x7f7f7f7f;
- for(int x,i=1;i<=n;i++)x=read(),sum[i]=sum[i-1]+x;
- for(int i=1;i<=r;i++)
- {
- push(i);
- if(i>=l)ans=max(ans,sum[i]);
- }
- for(int i=2;i<=n-l+1;i++)
- {
- while(!q.empty()&&q.front()-i<l-1)q.pop_front();
- ans=max(ans,sum[q.front()]-sum[i-1]);
- if(i+r<=n)push(i+r);
- }
- write(ans);
- fclose(stdin);
- fclose(stdout);
- }