This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
int n;
int a[100005], b[100005];
int count(int l, int r){
int mx = -1;
for(int i=l; i<=r; i++) mx = max(mx, a[i]);
int cnt = 0;
for(int i=l; i<=r; i++){
if(mx == b[i]) cnt++;
}
return cnt;
}
int f(int now){
if(now > n) return 0;
int ret = 0;
for(int i=now; i<=n; i++){
ret = max(ret, count(now, i)+f(i+1));
}
return ret;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=1; i<=n; i++) cin>>b[i];
cout<<f(1)<<endl;
return 0;
}
# | 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... |