CodeForces462B
Appleman and Card Game
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
Appleman has n cards. Each card has an uppercase letter written on it. Toastman must choose k cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card i you should calculate how much Toastman's cards have the letter equal to letter on ith, then sum up all these quantities, such a number of coins Appleman should give to Toastman.
Given the description of Appleman's cards. What is the maximum number of coins Toastman can get?
Input
The first line contains two integers n and k (1 ≤ k ≤ n ≤ 105). The next line contains n uppercase letters without spaces — the i-th letter describes the i-th card of the Appleman.
Output
Print a single integer – the answer to the problem.
Sample Input
15 10
DZFDFZDFDDDDDDF
82
6 4
YJSNPI
4
//2016.8.2
#include<iostream>
#include<algorithm>
#include<cstring> using namespace std; int ch[]; bool cmp(int a, int b)
{
return a>b;
} int min(int a, int b)
{
return a > b ? b : a;
} int main()
{
int n, k;
long long ans, x;
char c;
while(cin >> n >> k)
{
memset(ch, , sizeof(ch));
getchar();
ans = ;
for(int i = ; i < n; i++)
{
c = getchar();
ch[c-'A']++;
}
sort(ch, ch+, cmp); for(int i = ; k > ;i++)
{
x = min(k, ch[i]);
ans += x*x;
k -= x;
}
cout << ans << endl;
}
return ;
}
CodeForces462B的更多相关文章
随机推荐
- html中DIv并排显示问题
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- unittest单元测试框架总结
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...
- Android学习笔记之Service
与服务通信 用bindservice 而startservice并无通信条件. service 为android为系统服务,所以程序员无法new出来,只能建立服务,共其他组件使用. package c ...
- SQL truncate 、delete与drop区别
SQL truncate .delete与drop区别 相同点: 1.truncate和不带where子句的delete.以及drop都会删除表内的数据. 2.drop.truncate都是DDL语句 ...
- (简单) POJ 3087 Shuffle'm Up,枚举。
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- 对position的理解
作者:zccst 先看看手册 值 描述 absolute 生成绝对定位的元素,相对于 static 定位以外的第一个父元素进行定位. 元素的位置通过 "left", "t ...
- css3动画-transition
当css属性改变的时候,控制animation的速度,让属性的变化发生在一段时间之内,而不是立即生效. 语法 transition: <property> <duration> ...
- STM32驱动TEA5767收音机模块
Tea5767是飞利浦公司出的一款集成化的收音机芯片,大四的时候机缘巧合遇到了这个芯片,用了一下,写点资料 主要特性 TEA5767HN是一款低功耗立体声收音IC,广泛应用于手机MP3 .MP 4 播 ...
- 机器人局部避障的动态窗口法(dynamic window approach) (转)
源:机器人局部避障的动态窗口法(dynamic window approach) 首先在V_m∩V_d的范围内采样速度: allowable_v = generateWindow(robotV, ro ...
- 2017-01-11小程序form表单提交
小程序form表单提交 1.小程序相对于之前的WEB+PHP建站来说,个人理解为只是将web放到了微信端,用小程序固定的格式前前端进行布局.事件触发和数据的输送和读取,服务器端可以用任何后端语言写,但 ...