Bear and five Cards

Source: Internet
Author: User

#include <stdio.h>
int main ()
{
int a[5],flag[2]={1,1},same[2]={0},ans=0;
for (int i=0;i<5;i++)
{
scanf ("%d", &a[i]);
Ans+=a[i];
}
for (int k=0,i=0;i<5;i++)
{
if (flag[k]>1) k++;
for (int j=i+1;j<5;j++)
{
if (a[j]==a[i]&&a[j]>0)
{
Same[k]=a[i];
flag[k]++;
a[j]=0;
}
}
}
if (flag[0]>3) flag[0]=3;
ans-=flag[0]*same[0]>flag[1]*same[1]?flag[0]*same[0]:flag[1]*same[1];
printf ("%d\n", ans);
return 0;
}

/*

A. Bear and Five cardstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard OUTP Ut

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

Limak can discard (throw out) some cards. His goal was to minimize the sum of numbers written in remaining (not discarded) cards.

He is allowed to at most once discard, or three cards with the same number. Of course, he won ' t discard cards if it ' s impossible to choose 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.

Examplesinput
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 have cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.

    • Do nothing and the sum of would be 7 + 3 + 7 + 3 + =.
    • Remove the cards with a number 7. The remaining sum would be 3 + 3 + =.
    • Remove the cards with a number 3. The remaining sum would be 7 + 7 + =.

You were asked to minimize the sum of so the answer is .

In the second sample, it's impossible to find or three cards with the same number. Hence, Limak does nothing and the sum is 7 + 9 + 1 + 3 + 8 =.

In the third sample, all cards has the same number. It ' s optimal to discard any three cards. The sum of the remaining numbers is ten + ten = 20.*/

Bear and five Cards

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.