A- Bear and Five Cards(codeforces ROUND356 DIV2)

时间:2023-03-09 21:34:33
A- Bear and Five Cards(codeforces ROUND356 DIV2)

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个数,只能删除其中2个或3个相同的数,输出最小的和 。

这道题其实只要统计(数字范围小于100,可桶排)  每个数字出现的次数,然后对出现二次以上的数字枚举减去他们的结果,然后输出最小的那个答案就可以了。

我蠢就蠢在 老是想暴力  枚举,并没有换一个思路换一个思想方面考虑问题,所以写的蠢了

我一开始只是排序后删除最大的2 或 3 个相同数字 ( 取决于最大的相同的有几个),当时知道有可能会出现删除2个最大的不如删除3个最小的情况,赌了一下数据会不会比较弱…… 事实证明CF的数据是很强力的。

下次不应该赌……

错误代码:

#include<algorithm>

#include<iostream>

using namespace std ;

bool comp( int a , int b )

{

return ( a>b) ;

}

int main()

{

int a[5];

for ( int i = 0 ; i < 5 ; i++)

cin >> a[i];

sort(a,a+5,comp);

for ( int i = 0 ; i < 5 ; i++)

{int cnt = 0 ;

int flag = 0 ;

for( int j = i+ 1 ; j < 5 ; j++ )

{int temp = a[i] ;

if( cnt == 2 )break ; 

if( a[i] == a[j] )

{a[i] = 0 ;

cnt++;

flag = 1 ;

}

if( temp == a[j] )

{

a[j] = 0 ;

cnt++ ; 

}

}

if ( flag == 1 ) break ; 

}

cout << a[0]+a[1]+a[2]+a[3]+a[4] << endl ; 

}

AC代码:

#include<iostream>

#include<cstring>

using namespace std ;

int main()

{

int a[5] , cnt[110] , s = 0 , ans ;

memset(cnt,0,sizeof(cnt));

for( int i = 0 ; i < 5 ; i++)

{

cin >> a[i] ;

cnt[a[i]]++;

s+=a[i];

}

ans = s ;

for ( int i = 0 ; i < 5 ; i++ )

{

int k ;

if( cnt[a[i]] ==  2 )

k = s - (a[i] << 1) ;

else if( cnt[a[i]] > 2 )

k = s - a[i] * 3 ;

if( k < ans )

ans = k ;

}

cout << ans << endl ;

}