Codeforces Round #294 (Div. 2) -- C. A and B and Team Training
C. A and B and Team Trainingtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
A and B are preparing themselves for programming contests.
An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. therefore, during the next team training A decided to make teams so that newbies are solving problems together with experienced fig.
A believes that the optimal team of three people shoshould consist of one experienced participant and two newbies. Thus, each experienced participant ipant can share the experience with a large number of people.
However, B believes that the optimal team showould have two experienced members plus one newbie. Thus, each newbie can gain more knowledge and experience.
As a result, A and B have decided that all the teams during the training session shoshould belong to one of the two types described above. furthermore, they agree that the total number of teams shocould be as much as possible.
There areNExperienced members andMNewbies on the training session. Can you calculate what maximum number of teams can be formed?
Input
The first line contains two integersNAndM(0? ≤?N,?M? ≤? 5. 105)-the number of experienced participant ipants and newbies that are present at the training session.
Output
Print the maximum number of teams that can be formed.
Sample test (s) input
2 6
Output
2
Input
4 5
Output
3
Note
Let's represent the experienced players as XP and newbies as NB.
In the first test the teams look as follows: (XP, NB, NB), (XP, NB, NB ).
In the second test sample the teams look as follows: (XP, NB, NB), (XP, NB, NB), (XP, XP, NB ).
Idea: Try to maximize that teams.
AC code:
#include
#include
#include
#include #include
using namespace std;int main() {int n, m;while(scanf("%d %d", &n, &m) != EOF) {int a = (m + n) / 3;int ans = min(a, min(n, m));printf("%d\n", ans);}return 0;}