A. Bear and Five Cards
題目連接:
http://www.codeforces.com/contest/680/problem/A
Description
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.
Sample Input
7 3 7 3 20
Sample Output
7 3 7 3 20
Hint
題意
你現在有五張牌,你可以刪去相同的兩張,或者三張,問你刪去之后,這五張牌最小的和是多少?
題解:
模擬一遍就好了,模擬刪除哪幾張就行了……
代碼
#include<bits/stdc++.h>
using namespace std;
int n,x,sum,ans;
map<int,int>H;
int main()
{
n=5;
for(int i=0;i<n;i++){
scanf("%d",&x);
H[x]++;
sum+=x;
}
ans=sum;
for(auto v:H){
if(v.second>2)
ans=min(ans,sum-3*v.first);
if(v.second>1)
ans=min(ans,sum-2*v.first);
}
cout<<ans<<endl;
}