考点:简单模拟
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
int n;
int m, sum = 0;
scanf("%d", &n);
vector<int> res(n + 1);
for (int i = 1; i <= n; i++)
{
int temp;
scanf("%d", &temp);
sum += temp;
res[i] = sum;
}
scanf("%d", &m);
for (int i = 1; i <= m; i++)
{
int a, b, sum1 = 0, sum2 = 0;
scanf("%d %d", &a, &b);
if (a > b)
{
int temp = a;
a = b;
b = temp;
}
sum1 = res[b - 1] - res[a - 1];
sum2 = sum - sum1;
if (sum2 > sum1)
{
cout << sum1 << endl;
}
else
{
cout << sum2 << endl;
}
}
return 0;
}