A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards with the same number. Of course, he won't discard cards if it's impossible to choose two or three cards with the same number.
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — numbers written on cards.
Print the minimum possible sum of numbers written on remaining cards.
7 3 7 3 20
26
7 9 3 1 8
28
10 10 10 10 10
20
In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40.
- Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26.
- Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20 = 34.
You are asked to minimize the sum so the answer is 26.
In the second sample, it's impossible to find two or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 = 28.
In the third sample, all cards have the same number. It's optimal to discard any three cards. The sum of two remaining numbers is 10 + 10 = 20.
水题
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
int main()
{
// freopen("shuju.txt","r",stdin);
int a[10];
memset(a,0,sizeof(a));
int sum=0;
for(int i=1;i<=5;i++)
{
cin>>a[i];
sum+=a[i];
}
sort(a+1,a+1+5);
int mi=sum;
for(int i=5;i>1;i--)
{
if(a[i]==a[i-1]&&a[i]==a[i-2])
{
mi=min(mi,sum-a[i]*3);
}
if(a[i]==a[i-1])
{
mi=min(mi,sum-a[i]*2);
}
}
cout<<mi<<endl;
return 0;
}
小熊Limak正在玩一个游戏,手中持有五张带有正整数的卡片。本任务的目标是最小化剩余卡片上的数值之和,允许一次丢弃两到三张相同数字的卡片。
511

被折叠的 条评论
为什么被折叠?



