A. joystickstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Friends is going to play console. They has joysticks and only one charger for them. Initially first joystick is charged at a1 Percent and second one is charged at a2 Percent. You can connect charger to a joystick only at the beginning for each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connecte D to a charger).
Game continues while both joysticks has a positive charge. Hence, if at the beginning of minute some joystick was charged by 1 percent, it have to being connected to a charger, otherwise The game stops. If some joystick completely discharges (its charge turns to 0), the game also stops.
Determine the maximum number of minutes that game can last. It is prohibited to pause the game, I e. at each moment both joysticks should are enabled. It's allowed for joystick to being charged by more than percent.
Input
The first line of the input contains the positive integers a1 and a2 (1≤ a1, a2 ≤100), the initial charge level of first and second joystick respectively.
Output
Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged.
Examplesinput
3 5
Output
6
Input
4 4
Output
5
The main topic: There are two handles, we will give him the remaining power, each charge a minute will be more than 1% of the power, not charging will drop 2% of the electricity.
Idea: greedy, priority to choose the charge of less power, note two handle charge is 1 o'clock special circumstances
#include <stdio.h>intMain () {intA, B, t=0; scanf ("%d%d", &a, &b); while(a>=1&&b>=1) { if(a==1&&b==1) Break; if(a>b) {a-=2; b++; T++; } Else{b-=2; A++; T++; }} printf ("%d\n", T); return 0;}
Codeforces 651A Joysticks Greedy