-
Notifications
You must be signed in to change notification settings - Fork 1
/
1352D.cpp
53 lines (46 loc) · 1.19 KB
/
1352D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
short t;
scanf("%hd", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[n], sum = 0;
FOR(i, 0, n) {
scanf("%d", &arr[i]);
sum += arr[i];
}
int a = 0, b = 0, ai = 0, bi = n-1, init = 0;
int moves = init;
while (sum && ai <= bi) {
bool turn = moves & 1;
int tmp = 0;
if (turn) {
// BOB
while (tmp <= init && sum) {
b += arr[bi];
tmp += arr[bi];
sum -= arr[bi];
arr[bi] = 0;
bi--;
}
}
else {
// ALICE
while (tmp <= init && sum) {
a += arr[ai];
tmp += arr[ai];
sum -= arr[ai];
arr[ai] = 0;
ai++;
}
}
init = tmp;
moves++;
}
printf("%d %d %d\n", moves, a, b);
}
}