fork download
  1. // #pragma GCC optimize "trapv"
  2. #include <bits/stdc++.h>
  3. //#include <boost/multiprecision/cpp_int.hpp>
  4. using namespace std;
  5. //using namespace boost::multiprecision;
  6. #define bitcount(x) __builtin_popcount(x)
  7. #define ll long long int
  8. #define INF 1000000007
  9. #define PI 3.1415926535897932384626
  10. #define endl "\n"
  11. #define all(v) (v).begin(),(v).end()
  12. #define mems(x, y) memset(x, y, sizeof(x))
  13. const int mxN = 5e4;
  14. typedef pair<int, int> pii;
  15. typedef pair<ll, ll> pl;
  16. typedef vector<int> vi;
  17. typedef vector<ll> vl;
  18. typedef vector<pii> vpii;
  19. typedef vector<pl> vpl;
  20. typedef vector<vi> vvi;
  21. typedef vector<vl> vvl;
  22.  
  23. int main() {
  24. ios_base::sync_with_stdio(false);
  25. cin.tie(0);
  26. cout.tie(0);
  27. ll t; cin >> t;
  28. while (t--) {
  29. string s;
  30. cin >> s;
  31. ll k, x; cin >> k >> x; // k=delete , x= occuring of char.
  32. ll count = 0;
  33. //char arr[s.size()] = { 0 };
  34. int arr[26]={0}; /*For Counting all small letter frequency*/
  35. for (ll i = 0; i < s.size(); i++) {
  36. if (arr[s[i]-97] < x) { /* -97 as ascii will range from 97-112(small letter only)...thus after sub..0-25*/
  37. arr[s[i]-97]++;
  38. count++;
  39. }
  40. else {
  41. if (k > 0) k--;
  42. else break;
  43. }
  44. }
  45. cout << count << "\n";
  46. }
  47.  
  48. }
Success #stdin #stdout 0s 4560KB
stdin
3
abcdefagahai
0 1
abcdefagahai
1 1
abcdefagahai
2 1
stdout
6
7
8