forked from dseco/acmudec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12049.cpp
41 lines (27 loc) · 891 Bytes
/
12049.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
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int T,N,M,a[10000],b[10000];
scanf("%d",&T);
while(T--){
scanf("%d %d",&N,&M);
for(int i = 0;i < N;++i) scanf("%d",&a[i]);
for(int i = 0;i < M;++i) scanf("%d",&b[i]);
sort(a,a + N);
sort(b,b + M);
int ans = 0;
for(int i1 = 0,i2 = 0;i1 < N || i2 < M;){
int e1 = i1,e2 = i2,x;
if(i1 < N && i2 < M) x = min(a[i1],b[i2]);
else if(i1 < N) x = a[i1];
else x = b[i2];
while(e1 < N && a[e1] == x) ++e1;
while(e2 < M && b[e2] == x) ++e2;
ans += abs((e1 - i1) - (e2 - i2));
i1 = e1; i2 = e2;
}
printf("%d\n",ans);
}
return 0;
}