题目来源
https://codeforces.com/problemset/problem/1352/D
题目描述
AC题解
只要理解了题目就不难写出题解,因为博主目前只学了一些c++的基础,所以写了一堆。
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
long long int n, a[1010];
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
if (n == 1)
{
printf("1 %d 0\n", a[0]); continue;
}
int sum[100];
sum['a'] = a[0];
sum['b'] = 0;
int cnt = 1;
int left1 = 1, right1 = n - 1, a1 = a[0], b1 = 0;
char turn = 'b';
while (left1 <= right1)
{
if ( turn == 'a')
{
while ((sum['b'] >= sum['a']) && (left1 <= right1))
{
sum['a'] += a[left1++];
if ((left1 == right1)&&(sum['b'] >= sum['a']))
{
sum['a'] += a[left1++];
break;
}
}
turn = 'b';
cnt++;
a1 += sum['a'];
sum['b'] = 0;
}
else
{
while ((sum['a'] >= sum['b']) && (left1 <= right1))
{
sum['b'] += a[right1--];
if ((left1 == right1) && (sum['a'] >= sum['b']))
{
sum['b'] += a[right1--];
break;
}
}
turn = 'a';
cnt++;
b1 += sum['b'];
sum['a'] = 0;
}
}
printf("%d %d %d\n", cnt, a1, b1);
}
return 0;
}