651A. Joysticks

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int a,b,c=0;
  6. int i;
  7. cin>>a>>b;
  8. int mn =min(a,b);
  9. int mx =max(a,b);
  10.  
  11. while( max(mx,mn)>1 && min(mx,mn)>0){
  12.  
  13. if(mx>mn){
  14. mn = mn+1;
  15. mx=mx-2;
  16.  
  17. }
  18. else {
  19. mn =mn -2;
  20. mx = mx+1;
  21. }
  22.  
  23. //cout<<mn<<" "<<mx<<endl;
  24. c++;
  25. }
  26. cout<<c;
  27. return 0;
  28. }

Comments

Popular posts from this blog

Codeforce Problem 1703A. YES or YES?

1535A. Fair Playoff

Aptitude test assistant programmer 2018