1046 Shortest Distance (20 分)

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;
	}
}
上一篇:在Python C API中返回多元对象的元组


下一篇:Python:不带“