fork download
  1. /*
  2.   author : [ Godsent ]
  3.   created : 2025.08.31 16:27:54
  4. */
  5.  
  6. #include <bits/stdc++.h>
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9. #define el "\n"
  10. #define int long long
  11. #define lb lower_bound
  12. #define ub upper_bound
  13. #define fi first
  14. #define se second
  15. #define sz(x) ((int)(x).size())
  16. #define all(v) (v).begin(), (v).end()
  17. #define pb push_back
  18. #define prs(n) fixed << setprecision(n)
  19.  
  20. const int mod = 1e9 + 7;
  21. const int N = 2e5 + 5;
  22. const int INF = 1e18;
  23.  
  24. using namespace std;
  25. using namespace __gnu_pbds;
  26. template <typename T>
  27. using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  28.  
  29. int n, m;
  30. string s;
  31. map<char,int> mp;
  32.  
  33. signed main() {
  34. ios_base::sync_with_stdio(false);
  35. cin.tie(0);
  36. cout.tie(0);
  37.  
  38. #ifndef ONLINE_JUDGE
  39. freopen("test.in", "r", stdin);
  40. freopen("test.out", "w", stdout);
  41. #endif
  42.  
  43. cin >> n >> m >> s;
  44. for (auto &c : s) mp[c]++;
  45.  
  46. char node = 'a';
  47. int curr = 0;
  48. for (int i = 'a'; i <= 'z'; i++) {
  49. if (curr + mp[(char)i] < m) curr += mp[(char)i];
  50. else {
  51. node = (char)i;
  52. break;
  53. }
  54. }
  55.  
  56. for (int i = 0; i < n; i++) {
  57. if (curr == m) {
  58. cout << s[i];
  59. continue;
  60. }
  61. if (s[i] < node) continue;
  62. else if (s[i] == node) {
  63. curr++;
  64. continue;
  65. }
  66. cout << s[i];
  67. }
  68.  
  69. return 0;
  70. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty