Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
                                                        C++ Programming
#include <stdio.h>
using namespace std;
int a, b, res;
int main() {
	scanf("%d %d", &a, &b);
	res = 0;
	while(a > 0 && b > 0) {
		if(a < b) {
			b -= 2;
			++a;
		} else {
			a -= 2;
			++b;
		}
		++res;
		if(a < 0 || b < 0)
			--res;
	}
	printf("%d\n", res);
}Input
                                                            3 5
                                                                                                                    
                                                    Output
                                                            6
                                                                                                                    
                                                    Demonstration
Codeforces Solution-Joysticks-Solution in C, C++, Java, Python
