-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathp1.c
49 lines (36 loc) · 844 Bytes
/
p1.c
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
#include <stdlib.h>
#include <stdio.h>
void fr_incr(int* p, int n) {
p[2000 + n]++;
}
int fr_get(const int* p, int n) {
return p[2000 + n];
}
int main() {
FILE* fin = fopen("p1.in", "r");
int n, m;
fscanf(fin, "%d %d ", &n, &m);
int* a = (int*)calloc(sizeof(int), 4001);
int* b = (int*)calloc(sizeof(int), 4001);
for (int i = 0; i < n; ++i) {
int x;
fscanf(fin, "%d ", &x);
fr_incr(a, x);
}
for (int i = 0; i < m; ++i) {
int x;
fscanf(fin, "%d ", &x);
fr_incr(b, x);
}
fclose(fin);
int comune = 0;
for (int i = -2000; i <= 2000; ++i) {
int na = fr_get(a, i), nb = fr_get(b, i);
if (na && nb) {
comune += ((na < nb) ? na : nb);
}
}
printf("%d\n", comune);
free(a);
free(b);
}