Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #define N 5005
- using namespace std;
- int n, m, a[N], b[N], dp[N];
- int main() {
- freopen("interview.in", "r", stdin);
- freopen("interview.out", "w", stdout);
- cin >> n >> m;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- for (int j = 0; j < m; j++)
- cin >> b[j];
- for (int i = 0; i < n; i++) {
- for (int pos1 = 0, pos2 = 0, mx = 1; pos1 < m; pos1++) {
- while (b[pos1] != a[i] && pos1 < m) pos1++;
- if (pos1 == m) continue;
- for (; pos2 < pos1; pos2++)
- if (b[pos2] < b[pos1])
- mx = max(mx, dp[pos2] + 1);
- dp[pos1] = max(dp[pos1], mx);
- }
- }
- int ans = 0;
- for (int i = 0; i < m; i++)
- ans = max(ans, dp[i]);
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement