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

Input
15 10
DZFDFZDFDDDDDDF
Output
82
Input
6 4
YJSNPI
Output
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的更多相关文章

随机推荐

  1. fuel 6.1自动推送3控高可用centos 6.5 juno环境排错(一)

    查看fuel日志: # less /var/log/docker-logs/remote/node-1.domain.tld/puppet-apply.log 2015-12-25T17:26:22. ...

  2. UIScroll和UIPickView

    .h #import <UIKit/UIKit.h> #define WIDTH self.view.frame.size.width #define HEIGHT self.view.f ...

  3. Java 内存回收机制 -说到点上了

    下面这个图,很清楚地说明对象在new的时候是怎样开辟内存空间的 其中对象new出来的,是栈内存,变量的开辟是堆内存 Java的一个重要优点就是通过垃圾收集器GC (Garbage Collection ...

  4. TweenLite JS版

    今早逛网站看到下面这个帖子: 译~GreenSock动画平台(GSAP)的JavaScript版本入门 这个就是做ActionScript 的时候用得最多的第三方缓动包TweenLite了, 就此标记 ...

  5. 神经网络 Neuroph - Java Neural Network Platform Neuroph

    http://neuroph.sourceforge.net/image_recognition.html https://github.com/neuroph/neuroph

  6. OPENCV直方图与匹配

    直方图可以用来描述不同的参数和事物,如物体的色彩分布,物体的边缘梯度模版以及目标位置的当前假设的概率分布. 直方图就是对数据进行统计的一种方法,并且将统计值定义到一系列定义好的bin(组距)中,获得一 ...

  7. 在阿里云ECS(CentOS6.5)上安装mysql

    首先查看服务器上是否已经安装过mysql 命令: rpm -qa | grep mysql 结果: 可以看到ECS上已经有mysql-libs这个包了.这并不影响安装. 查看yum服务器上提供的mys ...

  8. N-gram语言模型简单介绍

    N-gram语言模型 考虑一个语音识别系统,假设用户说了这么一句话:"I have a gun",因为发音的相似,该语音识别系统发现如下几句话都是可能的候选:1.I have a ...

  9. Mysql中Insert into xxx on duplicate key update问题

    要点:Insert into xxx on duplicate key update可以在唯一索引重复的情况下,进行更新操作.           (1) 插入里边的字段应该只有一个 唯一索引:   ...

  10. IOS小技巧——使用FMDB时如何把一个对像中的NSArray数组属性存到表中

    http://blog.csdn.net/github_29614995/article/details/46797917 在开发的当中,往往碰到要将数据持久化的时候用到FMDB,但是碰到模型中的属性 ...