-
Notifications
You must be signed in to change notification settings - Fork 0
/
bersu_ball.cpp
46 lines (34 loc) · 866 Bytes
/
bersu_ball.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
#include <bits/stdc++.h>
using namespace std;
int solve(priority_queue<int, vector<int>, greater<int>> a, priority_queue<int, vector<int>, greater<int>> b){
int count = 0;
while(!a.empty() and !b.empty()){
auto smaller = min(a.top(), b.top());
auto greater = max(a.top(), b.top());
if( (greater - smaller) <= 1 ){
a.pop();
b.pop();
count++;
}
else
smaller == a.top()? a.pop() : b.pop();
}
return count;
}
int main(int argc, char const *argv[])
{
priority_queue<int, vector<int>, greater<int>> boys, girls;
int n, m, aux;
cin >> n;
while(n--){
cin >> aux;
boys.push(aux);
}
cin >> m;
while(m--){
cin >> aux;
girls.push(aux);
}
cout << solve(boys, girls) << endl;
return 0;
}