CodeForces 478C (贪心)



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.

Example
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.

题意 :题意就是 一个桌子可以布置三个气球,这三个气球不能是一样的,现在给你三种气球的总数,问你有多少种情况 。

思路:最初看到这道题 ,就是一组数同时对他们-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);
	}
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值