#include<iostream> #include<stdio.h> #include<stdlib.h> #include<math.h> #include<string.h> #include<algorithm> #include<map> #include<vector> #include<queue> using namespace std; const int MAXN=100005; int dis[MAXN],A[MAXN]; //dis[i]表示1号结点按顺时针到达i号结点顺时针的下一个结点的distance //A[i]表示i号与i+1号结点的距离 //key:每次查询left-》right,取dis(left,right)和sum-dis(left,right)最小值 int main(){ int sum=0,query,n,left,right;//记得sum要初始化。。 scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&A[i]); sum+=A[i]; //累加sum dis[i]=sum;//预处理dis数组 } scanf("%d",&query); for(int i=0;i<query;i++){ //query个查询 scanf("%d%d",&left,&right); //left->right if(left>right) swap(left,right); //left>right时交换 int temp=dis[right-1]-dis[left-1]; printf("%d\n",min(temp,sum-temp)); } system("pause"); return 0; }