SPOJ BIPCSMR16 想法

Team Building


To make competitive programmers of BUBT, authority decide to take regular programming contest. To make this contest more competitive and fruitful there are some rules given to balance a team:
1. Only 1st , 2nd and 3rd year student can participate. 
2. A team must have three members. 
3. All the member cannot be from same year. 

You need to find out the maximum number of teams can build up according to given rules.

Input

The first line of input contain an integer T (1<=T<=10000) test case. Next T line contains three positive integer X, Y and Z (1<=X, Y, Z<=2*10^9) separated by a space which denotes the number of participants from 1st, 2nd, and 3rd year student.

Output

You need to find out the maximum number of teams can build up according to given rules.

Example

Input
2
1 2 3
1 12 3
Output
2
4

题意:一年级有X个学生,二年级有Y个学生,三年级有Z个学生,组成一支队伍的规则如下
.只有一年级,二年级,三年级的学生能够参加
.一支队伍必须有3个人
.队伍的成员不能都来自同一个年级
求最多能够组成多少支队伍


题解:不妨设x<=y<=z:
1) 2*(x+y)<=z
这个时候能组成x+y支队伍。(两个z带一个x,两个z带一个y)
2) 2*(x+y)>z
我们来搞事情:把一年级和二年级合并成一个年级。[加强条件]
设有2个三年级学生的队伍数目为a,有1个三年级学生的队伍数目为b。
a + 2b = (x+y)
2a + b = z
解得:
a+b = (x+y+z)/3


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;
ll a[3];
int main(){  
    int t;
    scanf("%d",&t);
    while(t--){
    	scanf("%lld%lld%lld",a,a+1,a+2);
    	sort(a,a+3);
    	if(2*(a[0]+a[1])<=a[2])printf("%lld\n",a[0]+a[1]);
	    else printf("%lld\n",(a[0]+a[1]+a[2])/3);
    }
    return 0;  
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值