-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.cpp
56 lines (51 loc) · 1 KB
/
D.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
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
void run_cases() {
int n, l, r;
cin >> n >> l >> r;
vector<int> c(n);
for(int i=0;i<n;i++) {
cin >> c[i];
--c[i];
}
vector<int> L(n), R(n);
for(int i=0;i<n;i++) {
if(i < l) {
L[c[i]]++;
} else {
R[c[i]]++;
}
}
int ans = n;
for(int i=0;i<n;i++) {
int x = min(L[i], R[i]);
ans -= 2 * x;
L[i] -= x;
R[i] -= x;
l -= x;
r -= x;
}
int limit = abs(r - l) / 2;
int have = 0;
if(l < r) {
for(int i=0;i<n;i++) {
have += R[i] / 2;
}
} else {
for(int i=0;i<n;i++) {
have += L[i] / 2;
}
}
ans -= min(have, limit);
ans -= min(l, r);
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(nullptr);
int tests = 1;
cin >> tests;
for(int test = 1;test <= tests;test++) {
run_cases();
}
}