fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <algorithm>
  4. #include <sstream>
  5. #include <string>
  6. #include <cmath>
  7. #include <vector>
  8. #include <set>
  9. #include <functional>
  10. #include <map>
  11. #include <stack>
  12. #include <climits>
  13. #include <bitset>
  14. #include <numeric>
  15.  
  16.  
  17. using namespace std;
  18. #define fast cin.tie(nullptr);cout.tie(nullptr);ios_base::sync_with_stdio(false);
  19.  
  20.  
  21.  
  22. struct interval {
  23. long long l, r;
  24. bool operator<(const interval& other) const {
  25. return l < other.l;
  26. }
  27. };
  28.  
  29.  
  30.  
  31.  
  32. int main() {
  33. fast
  34.  
  35.  
  36. int n, k;
  37. string s;
  38. cin >> n >> k;
  39. cin >> s;
  40. vector<int> freq(26, 0);
  41. for (char c : s) {
  42. freq[c - 'a']++;
  43. }
  44. for (int i = 0; i < 26 && k > 0; i++) {
  45. if (freq[i] <= k) {
  46. k -= freq[i];
  47. freq[i] = 0;
  48. }
  49. else {
  50. freq[i] -= k;
  51. k = 0;
  52. }
  53. }
  54. string r = "";
  55. for (char c : s) {
  56. if (freq[c - 'a'] > 0) {
  57. r += c;
  58. freq[c - 'a']--;
  59. }
  60. }
  61. cout << r << endl;
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69. return 0;
  70. }
  71.  
  72.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout