Bear and Five Cards

Time Limit: 2 Sec  Memory Limit: 256 MB

Description

 

A little bear Limak plays a game. He has five cards. There is one numberwritten on each card. Each number is a positive integer.

Limak can discard (throw out) some cards. His goal is to minimize the sumof numbers written on remaining (not discarded) cards.

He is allowed to at most once discard twoor three cards with the same number. Of course, he won't discard cards if it'simpossible to choose two or three cards with the same number.

Given five numbers written on cards, cay you find the minimum sum ofnumbers 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 onremaining cards.

 

Sample Input

7 3 7 3 20

Sample Output

26

HINT



#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int a[6],flag[2]={1,1},same[2]={0,0},k,i,j,sum=0;
    for(i=0;i<5;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    for(i=0,k=0;i<5;i++)
    {
        if(flag[k]>1)k++;
        for(j=i+1;j<5;j++)
        {
            if(a[j]==a[i]&&a[i]!=0)
            {
                flag[k]++;
                same[k]=a[i];
                a[j]=0;
            }
        }
    }
    if(flag[0]>3)flag[0]=3;
    sum-=flag[0]*same[0]>flag[1]*same[1]?flag[0]*same[0]:flag[1]*same[1];
    cout<<sum<<endl;
    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值