-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmin_operations.cpp
48 lines (39 loc) · 1.01 KB
/
min_operations.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
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
int minInsAndDel(int A[], int B[], int N, int M) {
vector<int> lis;
unordered_set<int> s;
for(int i = 0; i < M ;i++){
s.insert(B[i]);
}
for(int i = 0; i < N ;i++){
if(s.find(A[i])!=s.end()){
auto it = lower_bound(lis.begin(),lis.end(),A[i]);
if(it==lis.end()){
lis.push_back(A[i]);
}else{
*it = A[i];
}
}
}
return N+M-2*lis.size();
}
};
int main() {
int t;
cin >> t;
while (t--) {
int N,M;
cin>>N>>M;
int A[N], B[M];
for(int i=0; i<N; i++)
cin>>A[i];
for(int i=0; i<M; i++)
cin>>B[i];
Solution ob;
cout << ob.minInsAndDel(A,B,N,M) << endl;
}
return 0;
}