1.题目介绍
2.考察点,难度
模拟现实类,问题转换题,最短路径,难度易
3.解题代码
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int sum = 0, N, M, a, b, temp, d;
scanf("%d",&N);
int distance[N+1] = {0};
for (int i = 1; i <= N; i++){
scanf("%d", &temp);
sum += temp;
distance[i] = sum;
}
scanf("%d", &M);
for (int i = 0; i < M; i++){
scanf("%d%d", &a, &b);
if (a > b) swap(a, b);
d = distance[b-1] - distance[a-1];
printf("%d\n", min(d, sum-d));
}
return 0;
}