-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1831B.cpp
More file actions
49 lines (48 loc) · 1.13 KB
/
Copy path1831B.cpp
File metadata and controls
49 lines (48 loc) · 1.13 KB
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
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int n;cin>>n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++)
{
cin>>a[i];
};
for (int i = 0; i < n; i++)
{
cin>>b[i];
};
vector<int> a_(2*n,0);
vector<int> b_(2*n,0);
int prev_a=a[0],prev_b=b[0],temp_a=1,temp_b=1;
for(int i=1;i<n;i++) {
if(a[i]==prev_a) temp_a++;
else {
a_[prev_a-1]=max(a_[prev_a-1],temp_a);
prev_a=a[i];
temp_a=1;
}
if(b[i]==prev_b) temp_b++;
else {
b_[prev_b-1]=max(b_[prev_b-1],temp_b);
prev_b=b[i];
temp_b=1;
}
}
a_[prev_a-1]=max(a_[prev_a-1],temp_a);
b_[prev_b-1]=max(b_[prev_b-1],temp_b);
int maxx=0;
for(int i=0;i<2*n;i++) {
maxx=max(maxx,a_[i]+b_[i]);
}
cout<<maxx<<'\n';
}
return 0;
}