Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- const int INF = 1000000000;
- const int mod = 1e9 + 7;
- const int N = 1e6 + 5;
- int dp[N];
- signed main()
- {
- int n;
- cin >> n;
- int a[n + 5];
- for(int i = 1; i <= n; i++){
- cin >> a[i];
- }
- dp[1] = 0;
- dp[2] = abs(a[2] - a[1]);
- for(int i = 3; i <= n; i++){
- dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]) , dp[i - 2] + abs(a[i] - a[i - 2]));
- }
- cout << dp[n] << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement