-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlice,Bob and andies.cpp
More file actions
70 lines (70 loc) · 1.59 KB
/
Copy pathAlice,Bob and andies.cpp
File metadata and controls
70 lines (70 loc) · 1.59 KB
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
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
vector<int>a;
for(int i=0; i<n; i++)
{
int x;
cin>>x;
a.push_back(x);
}
int alice=0;
int bob=0;
int a_sum=0;
int b_sum=0;
int moves=1;
while(a.begin()!=a.end())
{
vector<int>b;
if(moves%2==0)
{
int j=a.size()-1;
b_sum=0;
while(1)
{
b_sum=b_sum+a[j];
a[j]=0;
j--;
if(b_sum>a_sum || j<0)
{
break;
}
}
bob=bob+b_sum;
}
else
{
int i=0;
a_sum=0;
while(1)
{
a_sum=a_sum+a[i];
a[i]=0;
i++;
if(a_sum>b_sum || i>a.size())
{
break;
}
}
alice=alice+a_sum;
}
for(int k=0; k<a.size(); k++)
{
if(a[k]!=0)
b.push_back(a[k]);
}
a=b;
moves++;
}
cout <<moves-1<<" "<<alice<<" "<<bob<<endl;
}
return 0;
}