2019-12-15
15:25:34
#include <bits/stdc++.h>
#include<math.h>
using namespace std;
const int MAXN = 100005;
int main(){
int N;
cin>>N;
int temp[N+1];
for(int i=0;i<N+1;++i){
temp[i] = 0;
}
for(int i = 1;i<N+1;++i){
cin>>temp[i];
}
int K = 0;
cin>>K;
int result[K];
for(int i =0;i<K;++i){
result[i] = 0;
}
for(int i=0;i<K;++i){
int temp1 = 0,temp2 = 0;
cin>>temp1;
cin>>temp2;
int tempt = abs(temp1-temp2);//求差值
int tempt1 = N-tempt;//求N-差值
int minmum = min(temp1,temp2);
int result1 = 0;//正序结果
int t = minmum;
for(int j=0;j<tempt;++j){
//int t = minmum;
result1 += temp[t];
t++;
}
int result2 = 0;//逆序结果
int p;//p存放较大的数
if(minmum==temp1){
p = temp2;
}
if(minmum == temp2){
p = temp1;
}
int s = p;
for(int l=0;l<tempt1;++l){
if(s>N){
s = 1;
}
result2 += temp[s];
s++;
}
result[i] = min(result1,result2);
}
for(int i=0;i<K;++i){
cout<<result[i]<<endl;
}
system("pause");
return 0;
}