303229: CF628C. Bear and String Distance

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Bear and String Distance

题意翻译

**题目描述:** ------------ Limak是一只小北极熊。他喜欢单词——只由小写字母构成,长度为n的单词。 他规定dist(s,s')的值为s与s'在26个字母中的间距。如,dist(c,e)=dist(e,c)=2,dist(a,z)=dist(z,a)=25。 而且,当dist两个单词时,其值为dist第一个字母+dist第二个字母+…… 如,dist(af,db)=dist(a,d)+dist(f,b)=3+4=7,dist(bear,roar)=16+10+0+0=26。 现在,Limak给你一个字母或单词s和值k,令你寻找一个s'使dist(s,s')=k。输出s'。如果没有合适的s',输出-1。 注意:最好用标准输入输出流,如C++的cin和cout,Java的Scanner/System.out 。 **输入格式** ------------ 第一行输入两个数:n和k。 ( 1<=n<=10^5 , 0<=k<=10^6 )。 第二行输入只由小写字母构成,长度为n的单词s。 **输出格式** ------------ 如果没有合适的s',输出-1。 否则,输出s',令dist(s,s')=k。 **输入输出样例** ------------ **输入#1** 4 26 bear **输出#1** roar **输入#2** 2 7 af **输出#2** db **输入#3** 3 1000 hey **输出#3** -1

题目描述

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, ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628C/8da66884325cabbb3822b7a59fabab06b8c9aecb.png), and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628C/020a67d9684ce0de62952b277c91f6ba625d786b.png). Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628C/88d3180afa5197edf3d9181b6092568129b849de.png), and ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628C/fb925baf4ad15f3149211e4c7e1c24edfeeed3f5.png). Limak gives you a nice string $ s $ and an integer $ k $ . He challenges you to find any nice string $ s' $ that ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628C/6ced56c16665504eebcfadbb27cc9012566c4756.png). 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 use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

输入输出格式

输入格式


The first line contains two integers $ n $ and $ k $ ( $ 1<=n<=10^{5} $ , $ 0<=k<=10^{6} $ ). The second line contains a string $ s $ of length $ n $ , consisting of lowercase English letters.

输出格式


If there is no string satisfying the given conditions then print "-1" (without the quotes). Otherwise, print any nice string $ s' $ that ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF628C/6ced56c16665504eebcfadbb27cc9012566c4756.png).

输入输出样例

输入样例 #1

4 26
bear

输出样例 #1

roar

输入样例 #2

2 7
af

输出样例 #2

db

输入样例 #3

3 1000
hey

输出样例 #3

-1

Input

题意翻译

**题目描述:** ------------ Limak是一只小北极熊。他喜欢单词——只由小写字母构成,长度为n的单词。 他规定dist(s,s')的值为s与s'在26个字母中的间距。如,dist(c,e)=dist(e,c)=2,dist(a,z)=dist(z,a)=25。 而且,当dist两个单词时,其值为dist第一个字母+dist第二个字母+…… 如,dist(af,db)=dist(a,d)+dist(f,b)=3+4=7,dist(bear,roar)=16+10+0+0=26。 现在,Limak给你一个字母或单词s和值k,令你寻找一个s'使dist(s,s')=k。输出s'。如果没有合适的s',输出-1。 注意:最好用标准输入输出流,如C++的cin和cout,Java的Scanner/System.out 。 **输入格式** ------------ 第一行输入两个数:n和k。 ( 1<=n<=10^5 , 0<=k<=10^6 )。 第二行输入只由小写字母构成,长度为n的单词s。 **输出格式** ------------ 如果没有合适的s',输出-1。 否则,输出s',令dist(s,s')=k。 **输入输出样例** ------------ **输入#1** 4 26 bear **输出#1** roar **输入#2** 2 7 af **输出#2** db **输入#3** 3 1000 hey **输出#3** -1

加入题单

算法标签: