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. java异常处理的面试题

    package test; public class Test { public static int method(int i) throws Exception { try { return 10 ...

  2. nutz_web应用中主页跳转到登录页面的方式

    一.前言 web应用开发时,地址栏输入ip+port+appName,通常可以跳转到登录页面.以下便介绍我所知道并且验证过的三种跳转方式. 二.准备工作 需要使用到两个url的处理分别如下: @At( ...

  3. Python之Mysql及SQLAlchemy操作总结

    一.Mysql命令总结 1.创建库 create database test1; 2.授权一个用户 grant all privileges on *.* to 'feng'@'%' identifi ...

  4. 好纠结啊,JeeWx商业版本号和开源版本号有什么差别呢?

    好纠结啊,JeeWx商业版本号和开源版本号有什么差别呢? JeeWx开源版本号是一套基础微信开发平台.有基础的微信菜单.素材管理.微信对接等基础功能,适合于开发人员学习研究. JeeWx商业版本号是一 ...

  5. [LeetCode]Wildcard Matching 通配符匹配(贪心)

    一開始採用递归写.TLE. class Solution { public: bool flag; int n,m; void dfs(int id0,const char *s,int id1,co ...

  6. 链接提交-js代码推送进化版

    百度站长平台提供链接索引的自动提交JS脚本已经有一段时日了.用百度自己的话讲:JS链接推送代码以网页为最小对象,服务于全平台多终端,PC站和移动站均可使用.安装代码的页面在任意平台(浏览器.微信.微博 ...

  7. Controller methods and views

    https://docs.asp.net/en/latest/tutorials/first-mvc-app/controller-methods-views.html We have a good ...

  8. DNS tunnel的原理及实战

    DNS tunnel的原理及实战 摘自:http://netsec.ccert.edu.cn/zhengming/2011/11/01/%E8%BD%AC%E8%BD%BD%EF%BC%9Adns-t ...

  9. 产生冠军--hdoj

    产生冠军 Time Limit : 1000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissi ...

  10. 使用fastcgi部署django应用

    1.fastcgi和cgi的区别 1)CGI (Common Gateway Interface): 用来作为 Web Server 同 Python, PHP 等的通信手段.而在静态网页的时代, 只 ...