思路:水题
#include<bits\stdc++.h>
using namespace std;
int main()
{
int a[6];
scanf("%d%d%d%d%d",&a[1],&a[2],&a[3],&a[4],&a[5]);
sort(a+1,a+6);
int sum = 0;
for(int i = 1;i<=5;i++)
sum+=a[i];
int cc = 0,cc1=0;
for(int i = 5;i>=3;i--)
{
int temp=0;
if(a[i]==a[i-1]&&a[i-1]==a[i-2])
{
temp = 0;
temp+=a[i];
temp+=a[i-1];
temp+=a[i-2];
}
cc = max(cc,temp);
}
for(int i = 5;i>=2;i--)
{
int temp=0;
if(a[i]==a[i-1])
{
temp = 0;
temp+=a[i];
temp+=a[i-1];
}
cc1 = max(cc1,temp);
}
cc = max(cc,cc1);
cout << sum-cc << endl;
}
A. Bear and Five Cards
time limit per test
memory limit per test
input
output
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
Given five numbers written on cards, cay you find the minimum sum of numbers on remaining cards?
Input
The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti) — numbers written on cards.
Output
Print the minimum possible sum of numbers written on remaining cards.
Examples
input
7 3 7 3 20
output
26
input
7 9 3 1 8
output
28
input
10 10 10 10 10
output
20
Note
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 is7 + 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 is10 + 10 = 20.