沫璃邀请她的朋友参加周末的派对。沫璃买了3种颜色的气球,现在她要有这些气球来装饰餐桌,每个餐桌只用恰好3个气球装饰,要求3个气球的颜色不能完全一样,可以是2种或者3种颜色。沫璃想知道这些气球最多能装饰多少张餐桌。
分析:取出值最大的颜色,只要其他两种颜色加起来达到总颜色的1/3,那么答案是气球总数/3,如果达不到1/3,那么答案是气球总数减去最大值颜色。
#include<iostream>
using namespace std;
int main(){
int t;
while (cin >> t) { //t是次数
long long arr[101][3];
for (int i = 0; i < t; i++)
{
long long sum = 0;
long long max = 0;
for (int j = 0; j < 3; j++)
{
cin >> arr[i][j];
sum += arr[i][j];
if (arr[i][j] > max)
{
max = arr[i][j];
}
}
if ((sum/3) <= (sum - max))
{
cout << sum / 3 << endl;
}
else
{
cout << (sum - max) << endl;
}
sum = 0;
max = 0;
}
}
return 0;
}