Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int n;
- int arr[100005];
- int memo[100005];
- int main() {
- cin >> n;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- memo[i] = 2e9;
- }
- memo[0] = 0;
- for(int i = 0; i < n; i++) {
- if(i + 1 < n) {
- memo[i + 1] = min(memo[i + 1], memo[i] + abs(arr[i] - arr[i + 1]));
- }
- if(i + 2 < n) {
- memo[i + 2] = min(memo[i + 2], memo[i] + abs(arr[i] - arr[i + 2]));
- }
- }
- cout << memo[n - 1] << endl;
- return 0;
- }
- // fib(7) = fib(6) + fib(5)
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement