CF div2 499 A. Stages
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的更多相关文章
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- cf div2 239 D
D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 237 D
D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- cf div2 238 D
D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- cf div2 238 c
C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 235 D
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- AtCoder ABC 076D - AtCoder Express
传送门:http://abc076.contest.atcoder.jp/tasks/abc076_d 本题是一个运动学问题——匀变速运动. 一个质点,从静止开始运动.按照速度限制,可将运动划分成n个 ...
- BZOJ 2085 luogu P3502 [POI2010]Hamsters (KMP、Floyd、倍增)
数组开小毁一生-- 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2085 这题在洛谷上有个条件是"互不包含",其实 ...
- HDU 2795 Billboard (线段树+贪心)
手动博客搬家:本文发表于20170822 21:30:17, 原地址https://blog.csdn.net/suncongbo/article/details/77488127 URL: http ...
- cnblogs正式启用
额,因为最近发现CSDN越来越过分了...现在连数学公式都显示错字体了--于是决定把博客搬至cnblogs. Markdown 测试 \(\frac{-b\pm \sqrt{b^2-4ac}}{2a} ...
- raize5的修改。
( ( ; Col1: $; Col2: $; Col3: $; Col4: $ ), ( ; Col1: $; Col2: $FA; Col3: $; Col4: $ ), ( ; Col1: $C ...
- rabbit-入门
#启用rabbit的web管理 rabbitmq-plugins.bat enable rabbitmq_management 发布的窗口用TOPIC模式 rabbitmq没有确认消息接收的返回值,M ...
- HDU 1515
简单题,直接用STACK模拟整个过程. 模拟出栈时,应注意保护现场,等到递归完成后返回. #include <iostream> #include <string.h> #in ...
- iOS总结(自己定义button)
1.首先新建一个类该类继承UIButton 2.实现几个方法 1).改动字体的一些属性 -(instancetype)initWithFrame:(CGRect)frame{ self = [supe ...
- vue+element-ui实现前端分页
按照他的文档来写分页 最主要的是 el-table里面展示的数据怎么处理 <el-table :data="AllCommodityList.slice((currentPage-1 ...
- /proc/sysrq-trigger说明【转】
本文转载自:http://blog.csdn.net/silenttung/article/details/8084136 版权声明:本文为博主原创文章,未经博主允许不得转载. /proc/sysrq ...