You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?
Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.
The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.
Print a single integer t — the maximum number of tables that can be decorated in the required manner.
5 4 3
4
In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively.
题意:给你三种颜色的气球, 现在让你从中选出三个,满足:最多有两个气球的颜色是一样的。问你这样满足条件的方案数
题解: 我们来对三种气球的数量排序,从大到小a,b,c,
如果a/2>=b+c显然最多就是b+c;画个图,就知道了
那么就只有 (a+b+c)/3这种解了
///1085422276 #include<bits/stdc++.h> using namespace std ; typedef long long ll; #define mem(a) memset(a,0,sizeof(a)) #define meminf(a) memset(a,127,sizeof(a)); #define inf 1000000007 #define mod 1000000007 inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); } while(ch>='0'&&ch<='9'){ x=x*10+ch-'0';ch=getchar(); }return x*f; } //************************************************ const int maxn=20000+5; ll c[maxn]; ll ans; int main(){ for(int i=1;i<=3;i++){ scanf("%I64d",&c[i]); } sort(c+1,c+3+1); if(c[1]+c[2]<=c[3]/2){ ans=c[1]+c[2]; } else if(c[1]+c[2]<=c[3]) { ans=(c[1]+c[2]+c[3])/3; } else if(c[1]+c[2]>c[3]){ ans=(c[1]+c[2]+c[3])/3; } cout<<ans<<endl; return 0; }