-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathc.cpp
58 lines (54 loc) · 1.48 KB
/
c.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
#include <bits/stdc++.h>
#define endl "\n"
#define eat cin
#define moo cout
#define int long long
using namespace std;
int T, N, M;
vector<int> apos, aneg, bpos, bneg;
int solve(vector<int> &a, vector<int> &b){
vector<int> sat;
for(int i : a){
if(binary_search(b.begin(), b.end(), i)){
sat.push_back(i);
}
}
int ans = sat.size();
int pushed = 0;
for(int i : b){
while(pushed < (int)a.size() && a[pushed] - pushed <= i){
pushed++;
}
int r = i + pushed - 1;
int inc = upper_bound(b.begin(), b.end(), r) - lower_bound(b.begin(), b.end(), i);
inc += sat.end() - upper_bound(sat.begin(), sat.end(), r);
ans = max(ans, inc);
}
return ans;
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
eat >> T;
while(T--){
apos.clear(), aneg.clear();
bpos.clear(), bneg.clear();
eat >> N >> M;
for(int i = 0; i < N; i++){
int x; eat >> x;
if(x > 0) apos.push_back(x);
else aneg.push_back(-x);
}
for(int i = 0; i < M; i++){
int x; eat >> x;
if(x > 0) bpos.push_back(x);
else bneg.push_back(-x);
}
sort(apos.begin(), apos.end());
sort(aneg.begin(), aneg.end());
sort(bpos.begin(), bpos.end());
sort(bneg.begin(), bneg.end());
int pos = solve(apos, bpos);
int neg = solve(aneg, bneg);
moo << pos + neg << endl;
}
}