this problem can be solved using deque easily. below is the code::: ______________________________________________________________________________________________________________
include<bits/stdc++.h>
using namespace std; int main() {int a; cin>>a; while(a--) { int q,w; cin>>q; deque dq; for(int i=0;i<q;i++) { cin>>w; dq.push_back(w); } int p=-1; int moves=0,alice=dq.front(),alice_total=0,bob=0,bob_total=0; alice_total=alice; dq.pop_front(); while(dq.size()>0) { if(p==-1)//bob turn { bob=0; while(bob<=alice&&dq.size()>0) { bob+=dq.back();
// cout<<"bob "<<bob<<" "; dq.pop_back(); }bob_total+=bob; moves++; } else//alice turn { alice=0; while(alice<=bob&&dq.size()>0) { alice+=dq.front(); // cout<<"alice "<<alice<<" "; dq.pop_front(); } alice_total+=alice; moves++; } p=p*-1; } cout<<moves+1<<" "<<alice_total<<" "<<bob_total<<endl; } return 0;
}