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

Правка en1, от Ambuj123, 2020-05-11 17:53:52

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;

}

Теги problem :1352d

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en7 Английский Ambuj123 2020-05-11 18:06:20 407 Tiny change: '#include<b' -> '\n\n#include<b'
en6 Английский Ambuj123 2020-05-11 18:00:45 247
en5 Английский Ambuj123 2020-05-11 17:59:46 17 Tiny change: '#include<b' -> '[problem:1352D]\n#include<b'
en4 Английский Ambuj123 2020-05-11 17:57:29 202 problem is solved using properties of deque ::
en3 Английский Ambuj123 2020-05-11 17:56:26 88
en2 Английский Ambuj123 2020-05-11 17:55:14 23
en1 Английский Ambuj123 2020-05-11 17:53:52 1591 Initial revision (published)