Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define nl '\n'
int n, k;
string s;
int main() {
int t; cin >> t;
while(t--){
cin >> n >> k;
cin >> s;
if(n == k) {
cout << 0 << nl;
continue;
}
if(0 == k) {
cout << s << nl;
continue;
}
map<int, int> mp;
for(int i=1;i<(int)s.size() and k;++i){
if(i and s[i]>s[i-1]){
s.erase(s.begin()+i-1);
// cerr << i << endl;
k--;
i-=2;
continue;
}
}
while(k--) s.pop_back();
cout << s << nl;
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1006 Remove K Digits
- Contest
- Sylhet ICPC 2024 Collaborative Challenge: Episode 2
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-10-30 11:42:30
- Judged At
- 2024-11-11 02:34:50
- Judged By
- Score
- 100
- Total Time
- 2ms
- Peak Memory
- 616.0 KiB