-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path685C.cpp
More file actions
76 lines (74 loc) · 1.82 KB
/
685C.cpp
File metadata and controls
76 lines (74 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
int n, k;
scanf("%d %d", &n, &k);
string a, b;
cin >> a >> b;
int arr[26];
int brr[26];
memset(arr,0,sizeof(arr));
memset(brr,0,sizeof(brr));
int maximum1 = -1;
int maximum2 = -1;
for (int i = 0; i < n; i++)
{
arr[a[i]-97]++;
brr[b[i]-97]++;
maximum1 = max(maximum1,a[i]-97);
maximum2 = max(maximum2,b[i]-97);
}
string s1,s2;
if(maximum1 > maximum2){
printf("NO\n");
continue;
}
bool yes = false;
for (int i = 0; i < n; i++)
{
yes = false;
if(arr[b[i]-97] > 0){
s1.push_back(b[i]);
arr[b[i]-97]--;
yes = true;
}
else{
int c = b[i]-97;
// printf("%d\n",c);
for (int j = 24; j >= 0; j--)
{
if(j < c && arr[j] >= k){
arr[j]-=k;
arr[c] += (k-1);
s1.push_back(b[i]);
// printf("skdfs\n");
yes = true;
break;
}
}
if(yes){
continue;
}
else{
break;
}
}
}
if(!yes){
printf("NO\n");
}
else{
printf("YES\n");
// for (int i = 0; i < s1.size(); i++)
// {
// printf("%c",s1[i]);
// }
// printf("\n");
}
}
}