Advertisement
AshGir

gggg

Sep 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.    int n,k, r = 0;
  11.     cin>>n;
  12.     vector<int> d(n+1);
  13.  
  14.     for(int i = 1;i<=n;i++)
  15.     {
  16.         cin>>d[i];
  17.  
  18.     }
  19.     vector<int> b(n+1);
  20.     b[1] = d[1];
  21.     b[2] = d[2] - d[1];
  22.     for(int i = 3;i<=n;i++)
  23.     {
  24.         long a =   max( d[i] , d[i-1] )  - min ( d[i] , d[i-1] );
  25.         long z = 3 *  (max ( d[i] , d[i-2] )  - min ( d[i] , d[i-2] ) );
  26.         b[i] = min(a,z) + b[i-2];
  27.  
  28.  
  29.  
  30.     }
  31.     cout<<b[n]<<endl;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement