Code:

#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
inline int get(char x){ return x - 'a' + 1;}
int main()
{
int n,k, arr[100], cnt = 0, pre = -1, ans = 0;
scanf("%d%d",&n,&k);
char str[100];
scanf("%s",str + 1);
for(int i = 1;i <= n; ++i) arr[i] = get(str[i]);
sort(arr + 1, arr + 1 + n);
for(int i = 1;i <= n ; ++i)
if(arr[i] - pre > 1)
{
ans += arr[i];
pre = arr[i];
++cnt;
if(cnt == k) break;
}
if(cnt == k) printf("%d",ans);
else printf("-1");
return 0;
}
``

CF div2 499 A. Stages的更多相关文章

  1. cf div2 234 D

    D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  2. 离线dfs CF div2 707 D

    http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...

  3. cf div2 239 D

    D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  4. cf div2 236 D

    D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  5. cf div2 237 D

    D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...

  6. cf div2 238 D

    D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...

  7. cf div2 238 c

    C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. cf div2 235 D

    D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...

  9. cf div2 234 E

    E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. qt的关闭窗口

    .关闭主窗口并退出程序是 QApplication::exit() .如果是QDialog,就accept() 或 reject()在调用窗口中获取相关参数:void MainWindow::on_p ...

  2. Porting from Oracle to MySQL

    A potential customer asked my about porting her application from Oracle Database to MySQL. I always ...

  3. HDU - 3040 - Happy Girls

    先上题目: Happy Girls Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. Redis容量及利用计划

    在利用Redis过程当中,咱们发明了很多Redis分歧于Memcached,也差别于MySQL的特点.(本文首要会商Redis未启用VM撑持环境) 1. Schema MySQL: 需事先设计Memc ...

  5. c++ 打飞机游戏开发日志

    设计思路:控制台模式 初始化: 建立画面,初始化数据 游戏过程: 1.获取操作 2.修改数据 3.更新画面 结束: 关闭画面,delete动态分配数据 4.29日 创建游戏背景,实现飞机移动操作,实现 ...

  6. 黑马day07 登录注冊案例(一)

    简单介绍:依据三层架构的思想设计本案例. 1.搭建好开发环境 准备好须要的包和模拟数据库配置文件users.xml -->cn.itheima.dao -->cn.itheima.serv ...

  7. 基于ActiveMQ的消息中间件系统逻辑与物理架构设计具体解释

    1. 基本介绍与组件架构图 维基百科对消息中间件的定义是"Message-oriented Middleware is software infrastructure focused on ...

  8. SRM 622 D2L3: Subsets, math, backtrack

    题目:http://community.topcoder.com/stat?c=problem_statement&pm=10554&rd=15855 符合条件的集中非1的元素个数是非 ...

  9. Linux中的默认权限与隐藏权限(文件、文件夹)

    一个文件(或文件夹)拥有若干个属性.包含(r/w/x)等基本属性,以及是否为文件夹(d)与文件(-)或连接文件(l)等属性.此外,Linux还能够设置其它系统安全属性.使用chattr来设置.以lsa ...

  10. HDU 5218 The E-pang Palace (简单几何—2014广州现场赛)

    题目链接:pid=5128">http://acm.hdu.edu.cn/showproblem.php? pid=5128 题面: The E-pang Palace Time Li ...