#include<stdio.h>
#include<vector>
using namespace std;
int main(){
int n;
scanf("%d",&n);
vector<int> dis(n);
int sum=0;
vector<int> porder(n);
vector<int> rorder(n);
for(int i=0;i<n;i++){
porder[i] = sum;
int v;
scanf("%d",&v);
sum+=v;
dis[i]=v;
}
int rsum=0;
for(int i=n-1;i>=0;i--){
rsum+=dis[i];
rorder[i]=rsum;
}
int m;
scanf("%d",&m);
for(int i=0;i<m;i++){
int st,ed;
scanf("%d %d",&st,&ed);
int little = st<ed?st:ed;
int large = st<ed?ed:st;
int partSum= porder[little-1] + rorder[large-1];
int res = partSum<sum-partSum?partSum:sum-partSum;
// printf("sum:%d psum:%d sum-psum:%d res:%d\n",sum,psum,sum-psum,res);
printf("%d\n",res);
}
}
PAT Advanced 1046 Shortest Distance
最新推荐文章于 2024-06-14 10:00:29 发布