1046 Shortest Distance (20 分)
路是一个环
#include <iostream>
using namespace std;
int a[100100];
int main(){
int n, m, x, y, sum = 0;
cin >> n;
for(int i = 1; i <= n; ++i){
cin >> x;
a[i + 1] = a[i] + x;
sum += x;
}
cin >> m;
while(m--){
cin >> x >> y;
cout << min(abs(a[y] - a[x]), sum - abs(a[y] - a[x])) << endl;
}
}