Advertisement
Rofyda_Elghadban1

Untitled

Oct 22nd, 2023
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1.  #include <bits/stdc++.h>
  2.  #define ll long long
  3.  #define ull unsigned long long
  4.  #define pi 3.141592654
  5.  #define NUM 1e18
  6.  #define Mod  1'000'000'007
  7.  #define fixed(n) fixed<<setprecision(n)
  8.  #define cin(v) for(auto &i:v) cin >> i ;
  9.  #define cout(v) for(auto &i:v) cout << i  <<" ";
  10.  #define vowel(x) (x=='e'||x=='a'||x=='i'||x=='o'||x=='u')
  11.  #define small(x) (x>=97&&x<=122)
  12.  #define capital(x) (x>=65&&x<=90)
  13.  #define Tolower(s) transform(s.begin(),s.end(),s.begin(),::tolower);
  14.  #define Toupper(s) transform(s.begin(),s.end(),s.begin(),::toupper);
  15.  #define all(v) ((v).begin()), ((v).end())
  16.  #define allr(v) ((v).rbegin()), ((v).rend())
  17.  #define updmax(a,b) a=max(a,b)
  18.  #define updmin(a,b) a=min(a,b)
  19.  //#define ceil(a,b) ((a/b)+(a%b?1:0))
  20.  /* asc -> 1 2 3 ,des -> 3 2 1 */
  21.  /***********************************************************************************/
  22.  using namespace std;
  23.  void Rofyda_Elghadban(){
  24.   #ifndef ONLINE_JUDGE  
  25.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  26.    #endif
  27.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  28.  }
  29.  
  30.  void solve(){
  31.   int n,k;
  32.   cin>>n>>k;
  33.   string s;
  34.   cin>>s;
  35.   map<char,int>mp;
  36.   vector<int>o,e,v;
  37.   for(int i=0;i<s.size();i++){
  38.     mp[s[i]]++;
  39.   }
  40.   for(auto& i:mp){
  41.     if(i.second%2!=0){
  42.       o.push_back(i.second);
  43.     }else{
  44.       e.push_back(i.second);
  45.     }
  46.   }
  47.   sort(all(o));
  48.   sort(all(e));
  49.   for(int i=0;i<o.size();i++){
  50.     v.push_back(o[i]);
  51.   }
  52.   for(int i=0;i<e.size();i++){
  53.     v.push_back(e[i]);
  54.   }
  55.   int l=0,countero=0,countere=0;
  56.   for(int i=0;i<v.size();i++){
  57.     if(k>=v[i]){
  58.       l++;
  59.       k-=v[i];
  60.     }
  61.   }
  62.   for(int i=l;i<v.size();i++){
  63.     if(v[i]%2!=0){
  64.       countero++;
  65.     }
  66.   }
  67.   if(countero>1){
  68.     cout<<"NO"<<"\n";
  69.   }else{
  70.     cout<<"YES"<<"\n";
  71.   }
  72.  }
  73.  
  74.  
  75.  int main(){
  76.   Rofyda_Elghadban();
  77.   int t;
  78.   cin>>t;
  79.   while(t--){
  80.     solve();
  81.   }
  82.   // solve();
  83.   return 0;
  84.  }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement