Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n,k, r = 0;
- cin>>n;
- vector<int> d(n+1);
- for(int i = 1;i<=n;i++)
- {
- cin>>d[i];
- }
- vector<int> b(n+1);
- b[1] = d[1];
- b[2] = d[2] - d[1];
- for(int i = 3;i<=n;i++)
- {
- long a = max( d[i] , d[i-1] ) - min ( d[i] , d[i-1] );
- long z = 3 * (max ( d[i] , d[i-2] ) - min ( d[i] , d[i-2] ) );
- b[i] = min(a,z) + b[i-2];
- }
- cout<<b[n]<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement