Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- using namespace std;
- const int N=5000+17;
- int taba[N];
- int tabb[N];
- vector<long long >v1;
- vector<long long >v2;
- int n;
- int main()
- {
- cin>>n;
- for (int i=1; i<=n;i++)
- {
- cin>>taba[i];
- }
- for (int i=1; i<=n;i++)
- {
- cin>>tabb[i];
- v2.push_back(0);
- }
- v2.push_back(0);
- int ile =0;
- v1.push_back(0);
- for (int i=1; i<=n; i++)
- {
- for (int j=1; j<=n; j++)
- {
- if (taba[j]==tabb[i])
- {
- ile++;
- if ((max(v1[j-1],v2[j]))>v2[j-1]+taba[j])
- {
- v1.push_back(max(v1[j-1],v2[j]));
- }
- else
- {
- v1.push_back(v2[j-1]+taba[j]);
- }
- }
- else
- {
- v1.push_back(max(v1[j-1],v2[j]));
- }
- }
- v2=v1;
- v1.clear();
- v1.push_back(0);
- }
- if (ile=0)
- {
- cout<<0;
- return 0;
- }
- cout<<v2[n];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement