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() {
- int k;
- cin >> n >> k;
- for(int i = 0; i < n; i++) {
- cin >> arr[i];
- memo[i] = 2e9;
- }
- memo[0] = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 1; j <= k; j++) {
- if(i + j < n) {
- memo[i + j] = min(memo[i + j], memo[i] + abs(arr[i] - arr[i + j]));
- }
- }
- }
- cout << memo[n - 1] << endl;
- return 0;
- }
- // fib(7) = fib(6) + fib(5)
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement