ac了。。好水的題。。
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 100011;
int n,p;
i64 a[maxn];
int m,t;
i64 s[maxn];
int l,r;
i64 ans;
i64 now,to;
int main()
{
while(cin>>n>>p)
{
MM(a,0);
MM(s,0);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
s[0]=0;
for(int i=1;i<=n;i++)
{
s[i]=s[i-1]+a[i];
}
cin>>m>>t;
ans=0;
if(m/2>=t)
{
l = max(p-t,1);
r = min(p+t,n);
ans=s[r]-s[l-1];
cout<<ans<<endl;
continue;
}
else if(m%2==0)
{
l = p-t;
r = p+m/2;
while(l<=r && l<=p-m/2 && r>0)
{
now = max(l,1);
to = min(r,n);
ans = max(ans,s[to]-s[now-1]);
l+=2;
r++;
}
l = p-m/2;
r = p + t;
int now,to;
while(l<=r && l<=n && r>=p+m/2)
{
now = max(l,1);
to = min(r,n);
ans = max(ans,s[to]-s[now-1]);
l-=1;
r-=2;
}
cout<<ans<<endl;
continue;
}
else
{
l = p - t;
r = p + m/2;
now = max(l,1);
to = min(r,n);
ans = max(ans,s[to]-s[now-1]);
r++;
l++;
while(l<=r && l<=p-m/2 && r>0)
{
now = max(l,1);
to = min(r,n);
ans = max(ans,s[to]-s[now-1]);
l+=2;
r++;
}
l = p-m/2;
r = p + t;
int now,to;
now = max(l,1);
to = min(r,n);
ans = max(ans,s[to]-s[now-1]);
l--;
r--;
while(l<=r && l<=n && r>=p+m/2)
{
now = max(l,1);
to = min(r,n);
ans = max(ans,s[to]-s[now-1]);
l-=1;
r-=2;
}
cout<<ans<<endl;
continue;
}
}
return 0;
}
作者:zz_1215