forked from Anmol2307/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBRIDGE.cpp
92 lines (80 loc) · 1.6 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
* Author: Hakobyan Tigran
*/
#pragma comment(linker, "/STACK:60777216")
#define printTime(begin, end) printf("%.3lf\n", (double)(end - begin) / (double)CLOCKS_PER_SEC)
#include <string.h>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <functional>
#include <complex>
#include <iostream>
#include <fstream>
#include <sstream>
#include <bitset>
#include <limits>
#include <ctime>
#include <cassert>
#include <valarray>
using namespace std;
const int maxN = 1003;
struct pr {
int first;
int second;
pr () :
first(0),
second(0) {
}
pr(int first_, int second_) :
first(first_),
second(second_) {
}
};
bool operator < (const pr &ac, const pr &bc) {
if(ac.first < bc.first)
return true;
if(ac.first > bc.first)
return false;
return ac.second < bc.second;
}
int n;
pr a[maxN];
int f[maxN];
void init() {
scanf("%d", &n);
for(int i = 0; i < n; ++i) scanf("%d", &a[i].first);
for(int i = 0; i < n; ++i) scanf("%d", &a[i].second);
sort(a, a + n);
for(int i = 0; i < n; ++i)
f[i] = 1;
}
int main () {
int test_case;
scanf("%d", &test_case);
while(test_case--) {
init();
int answer = -1;
for(int i = 1; i < n; ++i) {
int mmax = 0;
for(int j = 0; j < i; ++j) {
if(a[j].second <= a[i].second)
mmax = max(mmax, f[j]);
}
f[i] = mmax + 1;
answer = max(answer, f[i]);
}
printf("%d\n", answer);
}
return 0;
}