#include <cstdio>
#include <numeric> //for accumulate
#include <algorithm>
using namespace std;
inline bool isEven(int a) { return !(a & 1); }
int main() {
int n;
int pos1, pos2;
while (scanf("%d", &n) != EOF) {
int a[n+1];
int sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
sum += a[i];
}
scanf("%d %d", &pos1, &pos2);
if (pos1 == pos2) {
int sum1 = accumulate(a+1, a+1+pos1, 0);
int sum2 = accumulate(a+pos1, a+1+n, 0);
int ans1 = max(sum1, sum2);
printf("%d %d\n", max(ans1, sum - ans1), min(ans1, sum - ans1));
} else if (pos1 < pos2) {
int dis1, dis2, ans1 = 0, ans2 = 0;
if (isEven(pos2 - pos1)) {
dis1 = pos1 + (pos2 - pos1) / 2;
dis2 = pos2 - (pos2 - pos1) / 2 + 1;
} else {
dis1 = pos1 + (pos2 - pos1) / 2;
dis2 = pos2 - (pos2 - pos1) / 2;
}
ans1 = accumulate(a + 1, a + 1 + dis1, 0);
ans2 = accumulate(a + dis2, a + 1 + n, 0);
printf("%d %d\n", ans1, ans2);
} else if (pos1 > pos2) {
int dis1, dis2, ans1 = 0, ans2 = 0;
if (isEven(pos1 - pos2)) {
dis1 = pos1 - (pos1 - pos2) / 2;
dis2 = pos2 + (pos1 - pos2) / 2 - 1;
} else {
dis1 = pos1 - (pos1 - pos2) / 2;
dis2 = pos2 + (pos1 - pos2) / 2;
}
ans1 = accumulate(a + dis1, a + 1 + n, 0);
ans2 = accumulate(a + 1, a + 1 + dis2, 0);
printf("%d %d\n", ans1, ans2);
}
}
return 0;
}
timus 2000. Grand Theft Array V
最新推荐文章于 2024-04-10 17:36:22 发布