C - Bear and Five Cards

來源:互聯網
上載者:User

標籤:

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

Input
7 3 7 3 20
Output
26
Input
7 9 3 1 8
Output
28
Input
10 10 10 10 10
Output
20

題意:共有5張卡,可將兩張或三張重複卡片扔掉,求扔掉後和的最小值。

 

排序後找到最大重複卡片和減掉即可。

 

附AC代碼:

 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7  8 int a[6]; 9 int main(){10     for(int i=0;i<5;i++){11         cin>>a[i];12     }13     sort(a,a+5);14     int ans=2,Max=0,sum=0;15     for(int i=0;i<5;i++){16         if(a[i]==a[i+1]){17             if(ans<=3)//最多扔三張 18             Max=max(Max,a[i]*ans);19             ans++;20         }21         else22         ans=2;23     }24     for(int i=0;i<5;i++){25         sum+=a[i];26     }27     cout<<sum-Max<<endl;28     return 0;29 }

 

C - Bear and Five Cards

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.