Codeforces Round #640 (Div. 4) problem: 1352D — Alice, Bob and Candies

Revision en5, by Ambuj123, 2020-05-11 17:59:46

1352D - Alice, Bob and Candies

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(); 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;

}

Tags problem :1352d

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English Ambuj123 2020-05-11 18:06:20 407 Tiny change: '#include<b' -> '\n\n#include<b'
en6 English Ambuj123 2020-05-11 18:00:45 247
en5 English Ambuj123 2020-05-11 17:59:46 17 Tiny change: '#include<b' -> '[problem:1352D]\n#include<b'
en4 English Ambuj123 2020-05-11 17:57:29 202 problem is solved using properties of deque ::
en3 English Ambuj123 2020-05-11 17:56:26 88
en2 English Ambuj123 2020-05-11 17:55:14 23
en1 English Ambuj123 2020-05-11 17:53:52 1591 Initial revision (published)