Codeforces-273(div2) C. Table Decorations

C. Table Decorations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 rg and b will find the maximum number t of tables, that can be decorated in the required manner.

Input

The single line contains three integers rg 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.

Output

Print a single integer t — the maximum number of tables that can be decorated in the required manner.

Sample test(s)
input
5 4 3
output
4
input
1 1 1
output
1
input
2 3 3
output
2
Note

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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值