forked from satruddh/Hacktoberfest2k22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergelis.cpp
58 lines (54 loc) · 1007 Bytes
/
mergelis.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>
#include<vector>
#include <algorithm>
#define ll long long
#define lld long double
#define lli long long int
#define sza(x) ((int)x.size())
#define all(a) (a).begin(),(a).end()
#define vll vector<long long int>
using namespace std;
bool compare(ll a , ll b)
{
if(a>b) return true;
return false;
}
int LIS(vector<int> arr)
{
multiset<int> s;
multiset<int>::iterator it;
int sizeOfarray = arr.size();
for (int i = 0; i < sizeOfarray; i++)
{
s.insert(arr[i]);
it = s.upper_bound(arr[i]);
if (it != s.end())
s.erase(it);
}
return s.size();
}
void solve()
{
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> b(m);
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
for (int i = 0; i < m; i++)
{
cin >> b[i];
}
cout << LIS(a) + LIS(b) << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
int t=1;
cin>>t;
for( int k=1;k<=t;k++){
solve();
}
return 0;
}