Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <deque>
- using namespace std;
- int k1,k2,t;
- deque<int>s1,s2;
- main()
- {
- int n;
- cin>>n;
- cin>>k1;
- for (int i = 0; i < k1; ++i){cin>>t;s1.push_back(t);}
- cin>>k2;
- for (int i = 0; i < k2; ++i){cin>>t;s2.push_back(t);}
- int f=0;
- while(!s1.empty()||!s2.empty()){
- if(s1.empty()){
- cout<<f<<" "<<2;
- break;
- }
- if(s2.empty()){
- cout<<f<<" "<<1;
- break;
- }
- int a=s1.front();
- int b=s2.front();
- s1.pop_front();
- s2.pop_front();
- if(a>b){
- s1.push_back(b);
- s1.push_back(a);
- }
- else if(a<b){
- s2.push_back(a);
- s2.push_back(b);
- }
- if(f>10000){
- cout<<"-1";
- break;
- }
- f++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement