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

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 7, 3, 7, 3 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 is 7 + 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 is 10 + 10 = 20.

___________________

题意: 给你5个数,只能删除其中2个或3个相同的数,输出最小的和 。

这道题其实只要统计(数字范围小于100,可桶排)  每个数字出现的次数,然后对出现二次以上的数字枚举减去他们的结果,然后输出最小的那个答案就可以了。

我蠢就蠢在 老是想暴力  枚举,并没有换一个思路换一个思想方面考虑问题,所以写的蠢了

我一开始只是排序后删除最大的2 或 3 个相同数字 ( 取决于最大的相同的有几个),当时知道有可能会出现删除2个最大的不如删除3个最小的情况,赌了一下数据会不会比较弱…… 事实证明CF的数据是很强力的。

下次不应该赌……

错误代码:

#include<algorithm>

#include<iostream>

using namespace std ;

bool comp( int a , int b )

{

return ( a>b) ;

}

int main()

{

int a[5];

for ( int i = 0 ; i < 5 ; i++)

cin >> a[i];

sort(a,a+5,comp);

for ( int i = 0 ; i < 5 ; i++)

{int cnt = 0 ;

int flag = 0 ;

for( int j = i+ 1 ; j < 5 ; j++ )

{int temp = a[i] ;

if( cnt == 2 )break ; 

if( a[i] == a[j] )

{a[i] = 0 ;

cnt++;

flag = 1 ;

}

if( temp == a[j] )

{

a[j] = 0 ;

cnt++ ; 

}

}

if ( flag == 1 ) break ; 

}

cout << a[0]+a[1]+a[2]+a[3]+a[4] << endl ; 

}

AC代码:

#include<iostream>

#include<cstring>

using namespace std ;

int main()

{

int a[5] , cnt[110] , s = 0 , ans ;

memset(cnt,0,sizeof(cnt));

for( int i = 0 ; i < 5 ; i++)

{

cin >> a[i] ;

cnt[a[i]]++;

s+=a[i];

}

ans = s ;

for ( int i = 0 ; i < 5 ; i++ )

{

int k ;

if( cnt[a[i]] ==  2 )

k = s - (a[i] << 1) ;

else if( cnt[a[i]] > 2 )

k = s - a[i] * 3 ;

if( k < ans )

ans = k ;

}

cout << ans << endl ;

}

A- Bear and Five Cards(codeforces ROUND356 DIV2)的更多相关文章

  1. 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 stand ...

  2. Codeforces Round #356 (Div. 2) A. Bear and Five Cards 水题

    A. Bear and Five Cards 题目连接: http://www.codeforces.com/contest/680/problem/A Description A little be ...

  3. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  4. codeforces 680A A. Bear and Five Cards(水题)

    题目链接: A. Bear and Five Cards //#include <bits/stdc++.h> #include <vector> #include <i ...

  5. 【BZOJ1004】Cards(组合数学,Burnside引理)

    [BZOJ1004]Cards(组合数学,Burnside引理) 题面 Description 小春现在很清闲,面对书桌上的N张牌,他决定给每张染色,目前小春只有3种颜色:红色,蓝色,绿色.他询问Su ...

  6. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  7. (CodeForces - 5C)Longest Regular Bracket Sequence(dp+栈)(最长连续括号模板)

    (CodeForces - 5C)Longest Regular Bracket Sequence time limit per test:2 seconds memory limit per tes ...

  8. 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)

    题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...

  9. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

随机推荐

  1. 使用mysqldump 对数据库进行备份的乱码问题

    最近在做项目的工程中,由于系统中需要提供数据库备份的功能,经过网上一番搜索,觉得采用简单的mysqldump (1)java代码 String backupSQL = "cmd /c mys ...

  2. 设计模式:Prototype 原型模式 - 同学你抄过别人的作业么?-clone()方法的使用

    原型模式: 通过某个类的实例来创建对象 使用原型模式的好处: 好处是什么呢?当我们需要多次重复的创建一个类的示例的时候,我们可以使用new但是,new不仅仅耗费内存而且,如果new 某个类的构造方法中 ...

  3. ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第四章:更高级的数据管理

    在这一章我们将学习如何正确地删除分类信息,如何向数据库填充种子数据,如何使用Code First Migrations基于代码更改来更新数据库,然后学习如何执行带有自定义错误消息的验证. 注意:如果你 ...

  4. 二度云抢先成为首批中国工信部(.vip/.xyz/.club)域名注册管理机构

    今天,工信部官网的公示文件显示,新通用顶级域名.vip..xyz以及.club域名注册局已正式获得工信部审批,成为中国境内合法的顶级域名注册管理机构,这标志着.vip..xyz以及.club域名成为首 ...

  5. [转载]关于shell脚本的基本语法

    关于shell脚本的基本语法 整理于:2014-03-31,何俭飞,mymladdr@sina.com 一.执行 1.shell脚本如果要被执行,一般地必须要有执行权限"x"(除了 ...

  6. 什么是MongoDB、特点、历史、下载和工具

    什么是MongoDB ?MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统.在高负载的情况下,添加更多的节点,可以保证服务器性能.MongoDB 旨在为WEB应用提供可扩展 ...

  7. bzoj1180,2843

    1180: [CROATIAN2009]OTOCI Time Limit: 50 Sec  Memory Limit: 162 MBSubmit: 967  Solved: 597[Submit][S ...

  8. 教你成为全栈工程师(Full Stack Developer) 〇-什么是全栈工程师

    作为一个编码12年的工程师老将,讲述整段工程师的往事,顺便把知识都泄露出去,希望读者能少走一些弯路. 这段往事包括:从不会动的静态网页到最流行的网站开发.实现自己的博客网站.在云里雾里的云中搜索.大数 ...

  9. angular1 实现页面切换及tag页面

    tag页面实现<div class="b_gray" style="padding-left:24px;border-bottom:1px solid #ccc&q ...

  10. brew install nvm

    brew install nvm mkdir ~/.nvm nano ~/.bash_profilectrl+x 退出 source ~/.bash_profile echo $NVM_DIR nvm ...