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.
题意:给你三个数,分别代表红绿蓝色气球的个数,然后然你装饰桌子,每个桌子不能用三个同样颜色的气球装饰,让你求最多能装饰几个桌子。
做法:写题的时候想着把最少的先弄掉,然后剩下的两个小的减1,大的减2这样下去,每做一次ans++,虽然过了pretest,但是果断被hack,这不是最优解。最优解应该是:对每个颜色来说所能用的真正数量应该是min(r,(b+g)*2),这样的意思就是假设r是r,b,g中最大的,然后用一个r对应b*2或者一个r对应g*2来装饰一个桌子。所以最后r=min(r,(b+g)*2);b=min(b,(r+g)*2);g=min(g,(b+r)*2),ans=(r+b+g)/3。
#include <iostream>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include<map>
#include <algorithm>
#include<ctime>
#define esp 1e-6
#define LL unsigned long long
#define inf 0x0f0f0f0f
using namespace std;
int main()
{
__int64 a,b,c;
__int64 ans;
while(scanf("%I64d%I64d%I64d",&a,&b,&c)!=EOF)
{
a=min(a,(b+c)*2);
b=min(b,(a+c)*2);
c=min(c,(a+b)*2);
ans=(a+b+c)/3;
printf("%I64d\n",ans);
}
return 0;
}