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