Codeforces Round #356 (Div. 2)-A. Bear and Five Cards(模拟)

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 t1t2t3t4 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 7373 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.


题意:
找出五个数中,出现2次以上的数,取最大次数,而且相乘积最大。

AC代码:

#include<iostream>
#include<functional>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define CRL(a) memset(a,0,sizeof(a))
#define QWQ ios::sync_with_stdio(0)
typedef unsigned __int64 LL;
typedef  __int64 ll;
const int T = 200000+50;
const int mod = 1000000007;
const double PI = 3.1415926535898;

int main()
{
#ifdef zsc
	freopen("input.txt","r",stdin);
#endif

	int n,h,k,i,j,a[10],num[1000];
	while(~scanf("%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4]))
	{
		int t3=0,t2=0,sum=0;
		memset(num,0,sizeof(num));
		for(int i=0;i<5;++i){
			sum += a[i];
			num[a[i]]++;
			if(num[a[i]]==2){
				t2 = max(t2,a[i]);
			}
			else if(num[a[i]]==3){
				t3 = max(t3,a[i]); 
			}
		}
		if(t2*2>t3*3){
			printf("%d\n",sum-t2*2);
		}
		else {
			printf("%d\n",sum-t3*3);
		}
	}

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值