Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //skp
- #include <bits/stdc++.h>
- #define ll long long
- #define fastio ios_base::sync_with_stdio(false), cin.tie(nullptr)
- using namespace std;
- const ll mod = 1000000007;
- int main()
- {
- fastio;
- ll tc = 1;
- cin >> tc;
- for (ll t = 0; t < tc; t++)
- {
- ll n, k;
- cin >> n >> k;
- string a, b;
- cin >> a;
- cin >> b;
- sort(a.begin(), a.end());
- sort(b.begin(), b.end());
- vector<char> aa, bb;
- bool flag = 0;
- for (ll i = 0; i < n; i++)
- {
- if (a[i] != b[i])
- {
- aa.push_back(a[i]);
- bb.push_back(b[i]);
- if(a[i]>b[i])
- flag = 1;
- }
- }
- map<char, ll> m, m1;
- for (ll i = 0; i < aa.size(); i++)
- {
- m[aa[i]]++;
- m1[bb[i]]++;
- if (aa[i] == 'z')
- {
- flag = 1;
- }
- }
- if (flag)
- cout << "No\n";
- else
- {
- ll freq = INT_MAX, freq2 = INT_MAX;
- for (ll i = 0; i < aa.size(); i++)
- {
- freq = min(freq, m[aa[i]]);
- freq2 = min(freq2, m1[bb[i]]);
- }
- if (freq < k || freq2<k)
- cout << "No\n";
- else
- cout << "Yes\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement