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