程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #294 (Div. 2) -- C. A and B and Team Training

Codeforces Round #294 (Div. 2) -- C. A and B and Team Training

編輯:C++入門知識

Codeforces Round #294 (Div. 2) -- C. A and B and Team Training


C. 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
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).





思路:就是盡可能得將那個teams最大,感覺真水啊這題


AC代碼:

#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;
}












  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved