CF A and B and Team Training (数学)

A and B and Team Training
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 participants.

A believes that the optimal team of three people should consist of one experienced participant and two newbies. Thus, each experienced participant can share the experience with a large number of people.

However, B believes that the optimal team should 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 should belong to one of the two types described above. Furthermore, they agree that the total number of teams should be as much as possible.

There are n experienced members and m newbies on the training session. Can you calculate what maximum number of teams can be formed?

Input

The first line contains two integers n and m (0 ≤ n, m ≤ 5·105) — the number of experienced participants 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




思路是使两个数在任意时刻的差都保持最小,所以每次将小的减一,大的减二,然后又重新判断大小,再次迭代,直接暴力,刚开始以为会T,没想到A了,不过估计有直接算的公式,有空研究下。

 1 #include <iostream>

 2 #include <cstring>

 3 #include <cstdio>

 4 #include <string>

 5 #include <algorithm>

 6 #include <cctype>

 7 #include <queue>

 8 using    namespace    std;

 9 

10 int    main(void)

11 {

12     int    min,max;

13     int    count;

14     int    temp;

15 

16     cin >> max >> min;

17     count = 0;

18 

19     while(1)

20     {

21         if(max < min)

22         {

23             temp = max;

24             max = min;

25             min = temp;

26         }

27 

28         min -= 1;

29         max -= 2;

30         if(min >= 0 && max >= 0)

31             count ++;

32         else

33             break;

34     }

35     printf("%d\n",count);

36 

37     return    0;

38 }

 

你可能感兴趣的:(ini)