思路:题目的意思是Alice是从左边开始吃,而Bob从右边开始吃,两个人轮流吃,Alice先开始,下一次吃的人要比上一次吃的人多,最后求出两个人每个人吃了多少颗糖果,以及轮流了多少次,只需要将过程模拟出来就行。
#include<bits/stdc++.h>
using namespace std;
int c[1010];
int main()
{
int t;cin>>t;
while(t--){
int n ;cin>>n;
for(int i=1;i<=n;i++)
cin>>c[i];
int l = 1,r = n;
int count1=0;
int flag = 0,x=0;
int a=0,b=0,now;
while(l<=r){
if(flag==0){
now = 0;
while(x>=now&&l<=r){
now = now+c[l++];
}
a = a+now;
flag = 1;count1++;
}
else{
now = 0;
while(x>=now&&l<=r){
now = now+c[r--];
}
b = b+now;
//cout<<"b"<<" "<<b;
flag = 0; count1++;
}
x = now;
}
cout<<count1<<" "<<a<<" "<<b<<endl;
}
return 0;
}