-
Notifications
You must be signed in to change notification settings - Fork 1
/
1927_C_Choose_the_different_ones.cpp
71 lines (66 loc) · 1.64 KB
/
1927_C_Choose_the_different_ones.cpp
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
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n, m, k;
cin >> n >> m >> k;
vector<int> arr1(n);
vector<int> arr2(m);
map<int, int> hashh1;
map<int, int> hashh2;
for(int i=0; i<n; i++){
cin >> arr1[i];
}
for(int i=0; i<m; i++){
cin >> arr2[i];
}
for(int i=0; i<n; i++){
hashh1[arr1[i]]++;
}
for(int i=0; i<m; i++){
hashh2[arr2[i]]++;
}
int res1 = 0;
int res2 = 0;
int common = 0;
for(int i=1; i<=k; i++){
if(hashh1[i] >= 1 && hashh2[i] == 0){
res1++;
}
if(hashh1[i] == 0 && hashh2[i] >= 1){
res2++;
}
if(hashh1[i] >= 1 && hashh2[i] >= 1){
common++;
}
}
// cout << res1 << " " << res2 << " " << common << endl;
if(res1 > (k/2) || res2 > (k/2)) cout << "NO" << endl;
else if(res1 == k/2 && res2 == k/2){
cout << "YES" << endl;
}
else if(common == k){
cout << "YES" << endl;
}
else if(res1+res2+common < k){
cout << "NO" << endl;
}
else{
if(res1 < (n/2)){
common -= (res1 -(n/2));
}
if(res2 < (n/2)){
common -= (res2 - (n/2));
}
if(common < 0){
cout << "yes" << endl;
}
else{
cout << "YES" << endl;
}
}
}
return 0;
}