Codeforces Round #356 (Div. 2) A

A. Bear and Five Cards
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard 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 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?

Input

The only line of the input contains five integers t1, t2, t3, t4 and t5 (1 ≤ ti ≤ 100) — 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 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.

题意: 给你5个数  只能删掉两个或者三个相同的数 输出剩下数的和的最小值

题解: 暴力找到    两个相同数的和的最大值exm1*2  三个相同数的和的最大值exm2*3 取较大的

       ans=sum-exm;

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #define ll __int64
 6 using namespace std;
 7 int a[10];
 8 int b[105];
 9 int main()
10 {    int sum=0;
11      int exm1=0,exm2=0,exm;
12      memset(b,0,sizeof(b));
13     for(int i=0;i<5;i++)
14     {
15      scanf("%d",&a[i]);
16      sum+=a[i];
17      b[a[i]]++;
18      if(b[a[i]]==2)
19      {
20          exm1=max(exm1,a[i]*2);
21      }
22      if(b[a[i]]==3)
23      {
24          exm2=max(exm2,a[i]*3);
25      } 
26     }
27     exm=max(exm1,exm2);
28     cout<<sum-exm<<endl;
29     return 0;
30 }
原文地址:https://www.cnblogs.com/hsd-/p/5572934.html