codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

628C.md (2024B)


      1 Source: https://codeforces.com/problemset/problem/628/C
      2 
      3 C. Bear and String Distance
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
     22 
     23 The distance between two letters is defined as the difference between their positions in the alphabet. For example, ![](https://espresso.codeforces.com/b94160a4d1c955e1b6cd4a0fe139f103c35ac73f.png), and ![](https://espresso.codeforces.com/7a05c5ca27b2dc782643b883e8a0bae7e3298e4f.png).
     24 
     25 Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, ![](https://espresso.codeforces.com/77f313bb7e669a438377b73e0dcdc89dc88f4a7a.png), and ![](https://espresso.codeforces.com/51de79586a12d9aa6a55105517514bcd173984a8.png).
     26 
     27 Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that ![](https://espresso.codeforces.com/586a7bce2dc944b81b116fca51344694db717b8b.png). Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so.
     28 
     29 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.
     30 
     31 Input
     32 
     33 The first line contains two integers *n* and *k* (1 ≤ *n* ≤ 105, 0 ≤ *k* ≤ 106).
     34 
     35 The second line contains a string *s* of length *n*, consisting of lowercase English letters.
     36 
     37 Output
     38 
     39 If there is no string satisfying the given conditions then print "-1" (without the quotes).
     40 
     41 Otherwise, print any nice string *s*' that ![](https://espresso.codeforces.com/586a7bce2dc944b81b116fca51344694db717b8b.png).
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 4 26  
     49 bear
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 roar
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 2 7  
     62 af
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 db
     69 ```
     70 
     71 Input
     72 
     73 ```
     74 3 1000  
     75 hey
     76 ```
     77 
     78 Output
     79 
     80 ```
     81 -1
     82 ```