Perfect Team CodeForces - 1221C(二分)

You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can’t have both at the same time.

So the team is considered perfect if it includes at least one coder, at least one mathematician and it consists of exactly three members.

You are a coach at a very large university and you know that cc of your students are coders, mm are mathematicians and xx have no specialization.

What is the maximum number of full perfect teams you can distribute them into?

Note that some students can be left without a team and each student can be a part of no more than one team.

You are also asked to answer qq independent queries.

Input
The first line contains a single integer qq (1≤q≤1041≤q≤104) — the number of queries.

Each of the next qq lines contains three integers cc, mm and xx (0≤c,m,x≤1080≤c,m,x≤108) — the number of coders, mathematicians and students without any specialization in the university, respectively.

Note that the no student is both coder and mathematician at the same time.

Output
Print qq integers — the ii-th of them should be the answer to the ii query in the order they are given in the input. The answer is the maximum number of full perfect teams you can distribute your students into.

Example
Input
6
1 1 1
3 6 0
0 0 0
0 1 1
10 1 10
4 4 1
Output
1
3
0
0
1
3
Note
In the first example here are how teams are formed:

the only team of 1 coder, 1 mathematician and 1 without specialization;
all three teams consist of 1 coder and 2 mathematicians;
no teams can be formed;
no teams can be formed;
one team consists of 1 coder, 1 mathematician and 1 without specialization, the rest aren’t able to form any team;
one team consists of 1 coder, 1 mathematician and 1 without specialization, one consists of 2 coders and 1 mathematician and one consists of 1 coder and 2 mathematicians.
裸的二分题。二分答案,判断能否组成。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

ll a,b,c;

inline bool check(ll x)
{
	if(a<x) return 0;
	if(b<x) return 0;
	if(a+b+c<3ll*x) return 0;
	return 1;
}
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld%lld%lld",&a,&b,&c);
		ll l=0,r=1e18+1,mid;
		ll ans=0;
		while(l<=r)
		{
			mid=l+r>>1;
			if(check(mid))
			{
				ans=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		cout<<ans<<endl;
	}
}

努力加油a啊,(o)/~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值