# 2013 长沙网络赛J题

#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define Maxn 100010
#define Maxm 200010
#define LL __int64
#define Abs(x) ((x)>0?(x):(-x))
#define lson(x) (x<<1)
#define rson(x) (x<<1|1)
#define inf 100000
#define lowbit(x) (x&(-x))
#define clr(x,y) memset(x,y,sizeof(x))
#define Mod 1000000007
using namespace std;
int num[Maxn],sum[Maxn],val[Maxn];
int main()
{
int n,m,i,j,x1,x2,x;
while(scanf("%d",&n)!=EOF){
for(i=1;i<=n;i++)
scanf("%d",num+i);
for(i=1;i<=n;i++)
scanf("%d",sum+i);
num[3]=sum[2]-sum[1];
for(i=4;i<=n;i++) if(num[i-3]>=0){
num[i]=sum[i-1]-sum[i-2]+num[i-3];
}
num[n-2]=sum[n-1]-sum[n];
for(i=n-3;i>=1;i--) if(num[i+3]>=0){
num[i]=sum[i+1]-sum[i+2]+num[i+3];
}
if(num[1]>=0) num[2]=sum[1]-num[1];
if(num[2]>=0) num[1]=sum[1]-num[2];
for(i=4;i<=n;i++) if(num[i-1]>=0&&num[i-2]>=0){
num[i]=sum[i-1]-num[i-1]-num[i-2];
}
x1=x2=0;
for(i=4;i<=n;i+=3) if(num[i]<0){
val[i]=val[i-3]-sum[i-2]+sum[i-1];
x1=max(x1,-val[i]);
}
for(i=5;i<=n;i+=3) if(num[i]<0){
val[i]=val[i-3]-sum[i-2]+sum[i-1];
x2=max(x2,-val[i]);
}
scanf("%d",&m);
while(m--){
scanf("%d",&x);
x++;
if(num[x]>=0){
printf("%d\n",num[x]);
continue;
}
if(x%3==1){
printf("%d\n",sum[1]-x2+val[x]);
continue;
}
printf("%d\n",sum[1]-x1+val[x]);
}
}
return 0;
}
posted @ 2013-09-23 20:42 fangguo 阅读(...) 评论(...) 编辑 收藏