Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define pb push_back
- #define SZ(v) ((int)((v).size()))
- void run () {
- int n, k;
- cin >> n >> k;
- string s;
- cin >> s;
- int freq[30] = {0};
- for (int i = 0; i < n; ++i) {
- freq[s[i] - 'a']++;
- }
- int pos = 26; // i considered it iterate over 'z'
- for (int i = 0; i < 26; ++i) {
- if (k >= freq[i]) {
- k -= freq[i];
- } else {
- pos = i; // i got the minimum char
- break;
- }
- }
- string res;
- int rem = k;
- for (int i = 0; i < n; ++i) {
- int cur_char = s[i] - 'a';
- if (cur_char > pos || (cur_char == pos && rem == 0)) {
- // so i can add this char in the result string
- res += s[i];
- } else if (cur_char == pos) {
- // here rem or k greater than or equal one so i have to reduce this operations
- --rem;
- }
- }
- cout << res << '\n';
- }
- int main () {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // freopen("/home/hamoudi/clion/hello.in", "rt", stdin);
- int tt;
- tt = 1;
- // cin >> tt;
- while (tt--)
- run();
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement