Wrong Answer
Code
//Muhimin
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve()
{
int n, m; cin >> n >> m;
string s; cin >> s;
for(char i = 'a'; i <= 'z'; i++){
if(m == 0){
break;
}
int l = n - 1, f = 0;
while(f < l){
if(m == 0){
break;
}
while(s[l] != i){
l--;
if(l <= f){
break;
}
}
while(s[f] <= i){
f++;
if(f >= l){
break;
}
}
if(l == f){
break;
}
if(s[l] == i && s[f] > i){
swap(s[l], s[f]);
f++, l--;
m--;
}
else if(s[l] != i){
l--;
}
else if(s[f] <= i){
f++;
}
else if(s[l] == i && s[f] <= i){
f++;
}
if(m == 0){
break;
}
}
if(m == 0){
break;
}
}
cout << s << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1, tc = 0;
cin >> t;
while(t--){
//cout << "Case " << ++tc << ": ";
solve();
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1058 Lexicographically Smallest String
- Contest
- Sylhet ICPC 2024 Collaborative Challenge: Episode 2
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-10-30 10:17:57
- Judged At
- 2024-11-11 02:35:07
- Judged By
- Score
- 5
- Total Time
- 1ms
- Peak Memory
- 364.0 KiB