0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 01:45:25 +00:00

E - Replace With the Previous, Minimize

https://codeforces.com/contest/1675/submission/155988940
This commit is contained in:
Baoshuo Ren 2022-05-06 00:04:51 +08:00
parent eddd861bda
commit eb6c31f605
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

54
Codeforces/1675/E/E.cpp Normal file
View File

@ -0,0 +1,54 @@
#include <iostream>
#include <string>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2e5 + 5;
int t, n, k, max, a[30];
std::string s;
signed main() {
std::ios::sync_with_stdio(false);
cin >> t;
while (t--) {
max = 0;
for (int i = 0; i < 26; i++) {
a[i] = i;
}
cin >> n >> k >> s;
for (int i = 0; i < s.size(); i++) {
int x = s[i] - 'a';
if (x > k) {
int t = x - (k - max);
for (int j = x; j >= t; j--) {
a[j] = t;
}
break;
}
for (int j = x; ~j; j--) {
a[j] = 0;
}
max = std::max(max, x);
}
for (int i = 0; i < s.size(); i++) {
cout << char(a[s[i] - 'a'] + 'a');
}
cout << endl;
}
return 0;
}