首页 技术 正文
技术 2022年11月15日
0 收藏 302 点赞 2,559 浏览 1598 个字

C. Bear and String Distancetime limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Limak is a little polar bear. He likes nice strings — strings of length n, consisting of lowercase English letters only.

The distance between two letters is defined as the difference between their positions in the alphabet. For example, codeforces 628C C. Bear and String Distance, and codeforces 628C C. Bear and String Distance.

Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, codeforces 628C C. Bear and String Distance, and codeforces 628C C. Bear and String Distance.

Limak gives you a nice string s and an integer k. He challenges you to find any nice string s‘ that codeforces 628C C. Bear and String Distance. Find any s‘ satisfying the given conditions, or print “-1” if it’s impossible to do so.

As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to usegets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead ofScanner/System.out in Java.

Input

The first line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 106).

The second line contains a string s of length n, consisting of lowercase English letters.

Output

If there is no string satisfying the given conditions then print “-1” (without the quotes).

Otherwise, print any nice string s‘ that codeforces 628C C. Bear and String Distance.

Examplesinput

4 26
bear

output

roar

input

2 7
af

output

db

input

3 1000
hey

output

-1

题意:

AC代码:

#include <bits/stdc++.h>
using namespace std;
const int N=1e5+4;
char s[N];
int n,k;
int main()
{
int num=0;
scanf("%d%d",&n,&k);
scanf("%s",s);
for(int i=0;i<n;i++)
{
num+=max(s[i]-'a','z'-s[i]);
}
if(k>num)cout<<"-1"<<"\n";
else
{
int sum;
for(int i=0;i<n;i++)
{
sum=max(s[i]-'a','z'-s[i]);
//cout<<sum<<endl;
if(sum<=k){
k-=sum;
if(s[i]-'a'>'z'-s[i])s[i]='a';
else s[i]='z';}
else if(sum>k&&k!=0)
{
if(s[i]-'a'>=k)
{
s[i]=s[i]-k;
}
else
{
s[i]=s[i]+k;
}
k=0;
}
printf("%c",s[i]);
} }
return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,023
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,513
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,360
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,143
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,774
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,852