Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. int k1,k2,t;
  8. deque<int>s1,s2;
  9. main()
  10. {
  11. int n;
  12. cin>>n;
  13.  
  14. cin>>k1;
  15. for (int i = 0; i < k1; ++i){cin>>t;s1.push_back(t);}
  16.  
  17. cin>>k2;
  18. for (int i = 0; i < k2; ++i){cin>>t;s2.push_back(t);}
  19.  
  20. int f=0;
  21. while(!s1.empty()||!s2.empty()){
  22. if(s1.empty()){
  23. cout<<f<<" "<<2;
  24. break;
  25. }
  26. if(s2.empty()){
  27. cout<<f<<" "<<1;
  28. break;
  29. }
  30. int a=s1.front();
  31. int b=s2.front();
  32. s1.pop_front();
  33. s2.pop_front();
  34.  
  35. if(a>b){
  36. s1.push_back(b);
  37. s1.push_back(a);
  38. }
  39. else if(a<b){
  40. s2.push_back(a);
  41. s2.push_back(b);
  42. }
  43. if(f>10000){
  44. cout<<"-1";
  45. break;
  46. }
  47. f++;
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement