Joysticks

Read Statement    

Implementation
Greedy
Math
DP

It is not good to charge one the entire time until the other one gets discharged, because by the time the lower one goes to 2%, it is good to charge this one or greedily choose the smallest one every minute, charge it and keep on playing, this will allow us to play more time as we aren’t allowing the smallest one to keep on discharging. Also the game only ends if the biggest one at the start of every minute is 1 or 0. So the while loop ends when the biggest is 0/1 or a1 x a2 < 2 (both are the same). This process is scripted beautifully in the code below.

        
CODE
import java.util.Scanner;
public class codeforces651A
{ 
	public static void main(String[] args) 
	{ 
		Scanner s=new Scanner(System.in);
		int m=s.nextInt(),n=s.nextInt(),x=0;
        while(m*n>=2)
        {
            if(m>n)
            {
                m=m-2;
                n=n+1;
            }
            else
            {
                n=n-2;
                m=m+1;
            }
            x++;
        }
        System.out.print(x);
    }
}