forked from vengateshsubramaniyan/Spoj-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBRIDGE.cpp
50 lines (48 loc) · 1007 Bytes
/
BRIDGE.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>
#define ll long long
#define ld long double
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vl vector< ll >
#define bug(a) cout<<a<<endl;
#define bug2(a,b) cout<<a<<" "<<b<<endl;
#define bug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl;
using namespace std;
bool cmpp(pair<int,int> a,pair<int,int> b)
{
if(a.first<b.first)
return true;
if(a.first>b.first)
return false;
return a.second<b.second;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
vector< pair<int,int> >bridge(n);
for(int i=0;i<n;i++)
scanf("%d",&bridge[i].first);
for(int i=0;i<n;i++)
scanf("%d",&bridge[i].second);
sort(bridge.begin(),bridge.end(),cmpp);
vector<int> res(n,1);
for(int i=1;i<n;i++)
{
for(int j=0;j<i;j++)
{
if(bridge[j].first<=bridge[i].first && bridge[j].second<=bridge[i].second && res[i]<res[j]+1)
res[i]=res[j]+1;
}
}
int ma=1;
for(int i=0;i<n;i++)
ma=max(ma,res[i]);
printf("%d\n",ma);
}
return 0;
}