Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include<vector>
  3. using namespace std;
  4. const int N=5000+17;
  5. int taba[N];
  6. int tabb[N];
  7. vector<long long >v1;
  8. vector<long long >v2;
  9. int n;
  10. int main()
  11. {
  12.     cin>>n;
  13.     for (int i=1; i<=n;i++)
  14.     {
  15.         cin>>taba[i];
  16.     }
  17.     for (int i=1; i<=n;i++)
  18.     {
  19.         cin>>tabb[i];
  20.         v2.push_back(0);
  21.     }
  22.     v2.push_back(0);
  23.     int ile =0;
  24.     v1.push_back(0);
  25.     for (int i=1; i<=n; i++)
  26.     {
  27.         for (int j=1; j<=n; j++)
  28.         {
  29.  
  30.             if (taba[j]==tabb[i])
  31.             {
  32.                 ile++;
  33.                 if ((max(v1[j-1],v2[j]))>v2[j-1]+taba[j])
  34.                 {
  35.                     v1.push_back(max(v1[j-1],v2[j]));
  36.                 }
  37.                 else
  38.                 {
  39.                     v1.push_back(v2[j-1]+taba[j]);
  40.                 }
  41.  
  42.             }
  43.             else
  44.             {
  45.                 v1.push_back(max(v1[j-1],v2[j]));
  46.             }
  47.         }
  48.         v2=v1;
  49.         v1.clear();
  50.         v1.push_back(0);
  51.     }
  52.     if (ile=0)
  53.     {
  54.         cout<<0;
  55.         return 0;
  56.     }
  57.     cout<<v2[n];
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement