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?≤? a 1,? a 2. ≤?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
Test instructions: In a sequence, when the number of increments is encountered, will feel happy, now give a group of numbers, ask can be happy several times
The main problems: first sequence from small to large, record all occurrences of the number of times, remove the most occurrences of the remaining number of the and can
#include <stdio.h>#include<string.h>#include<algorithm>using namespacestd;intn,a[1100],b[1100];BOOLcmpintXinty) { returnX>y;}intMain () {intI,j,ans; while(SCANF ("%d", &n)! =EOF) {ans=0; memset (b,0,sizeof(b)); for(i=0; i<n;i++) {scanf ("%d",&A[i]); B[a[i]]++; } sort (B,b+1100, CMP); for(i=1;i<1100; i++) ans+=B[i]; printf ("%d\n", ans); } return 0;}
Codeforces 651B Beautiful Paintings greedy