#include<bits/stdc++.h>
using namespace std;
int n;
int a[5005], b[5005];
int sus[5005][5005];
int f[5005];
namespace sub1{
void solve(){
for (int i = 1; i <= n; i++){
int mx = 0;
map<int, int> hihi;
for (int j = i; j <= n; j ++){
mx = max(mx, a[j]);
hihi[b[j]] ++;
sus[i][j] = hihi[mx];
}
}
for (int i = 1; i <= n; i ++){
for (int j = 1; j <= i; j ++){
f[i] = max(f[i], f[j - 1] + sus[j][i]);
}
}
cout << f[n] << endl;
}
};
namespace sub2{
};
namespace sub4{
};
int main(){
cin >> n;
for (int i = 1; i <= n; i ++){
cin >> a[i];
}
for (int i = 1; i <= n; i ++){
cin >> b[i];
}
sub1::solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |