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
1 1 1
1
2 3 3
2
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.
题意 :题意就是 一个桌子可以布置三个气球,这三个气球不能是一样的,现在给你三种气球的总数,问你有多少种情况 。
思路:最初看到这道题 ,就是一组数同时对他们-0,-1,-2,问你减到0,0,0有多少次,这样一看 ,是不是像是 搜索,但是数据范围巨大,肯定不是啦。。,所以最终解法是这样,对这三个数进行排序,前两个较小的数如果小于较大数的二倍的话,那么答案就是前两个数相加,为什么是这样,我们都知道 最好的方法就是在最大中取两个,最小的当中取一个,那么就是这样写的啦,然后 大于他的二倍的话到最后就不能这样分了,那么他最后肯定会剩下,那就直接除3,为什么,因为最后剩下的数肯定不会超过3,因为如果超过三的情况下那他就能在分出一个了,比如1,1,1;1,2,1这些都能再分出去,所以他剩下的总数不可能超过三 ,那么我们直接除3的话得到的就是最后答案
上代码:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
long long a[3];
scanf("%lld%lld%lld",&a[0],&a[1],&a[2]);
sort(a,a+3);
if((a[0]+a[1])*2<=a[2])
{
printf("%d\n",a[0]+a[1]);
}
else
{
printf("%d\n",(a[0]+a[1]+a[2])/3);
}
}