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;
const int MX = 2005;
int N;
int H[MX], T[MX], dp[MX];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> N;
for(int i = 1; i <= N; i++) cin >> H[i];
for(int i = 1; i <= N; i++) cin >> T[i];
for(int i = 1; i <= N; i++) {
int mx = H[i];
map<int,int> cnt;
cnt[T[i]]++;
for(int j = i - 1; j >= 0; j--) {
dp[i] = max(dp[i], dp[j] + cnt[mx]);
mx = max(mx, H[j]);
cnt[T[j]]++;
}
cnt.clear();
}
cout << dp[N] << '\n';
}
# | 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... |