-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1352D Alice, Bob and Candies.cpp
83 lines (82 loc) · 2.09 KB
/
1352D Alice, Bob and Candies.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
author : MishkatIT
created : Thursday 2023-03-16-18.01.58
*/
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(_) cout << #_ << " is " << _ << '\n';
using namespace std;
int main()
{
fio;
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
vector<int>v(n);
for (auto &i : v)
{
cin >> i;
}
vector<int> pre(n + 10), post(n + 10);
pre[0] = v[0];
for(int i = 1; i < n; i++)
{
pre[i] = pre[i - 1] + v[i];
}
post[n - 1] = v[n - 1];
for(int i = n - 2 ; i >= 0; i--)
{
post[i] = post[i + 1] + v[i];
}
int i, j, tempi, tempj;
i = 1, tempi = 0;
j = n - 1, tempj = n;
int toogle = 1, x = n - 1;
int alice = pre[0], bob = 0;
int last = pre[0], temp = 0;
while(x > 0)
{
if(toogle % 2 == 0)
{
toogle++;
for(; i < tempj; i++)
{
x--;
temp = pre[i] - pre[tempi];
if(temp > last)
{
last = temp;
alice += pre[i] - pre[i - 1];
tempi = i;
i++;
break;
}
alice += pre[i] - pre[i - 1];
}
}
else
{
toogle++;
for(; j > tempi; j--)
{
x--;
temp = post[j] - post[tempj];
if(temp > last)
{
last = temp;
bob += post[j] - post[j + 1];
tempj = j;
j--;
break;
}
bob += post[j] - post[j + 1];
}
}
}
cout << toogle << ' ' << alice << ' ' << bob << '\n';
}
return 0;
}