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 N = 1e5 + 5;
- const int mod = 1e18 + 7;
- const int INF = 1e18;
- int dp[N];
- int from[N];
- int a[N];
- signed main()
- {
- int n , k;
- cin >> n;
- for(int i = 1; i <= n; i++){
- cin >> a[i];
- }
- dp[2] = abs(a[2] - a[1]);
- from[2] = 1;
- for(int i = 3; i <= n; i++){
- if((dp[i - 1] + abs(a[i] - a[i - 1])) <= (dp[i - 2] + 3 * abs(a[i] - a[i - 2]))){
- from[i] = i - 1;
- dp[i] = dp[i - 1] + abs(a[i] - a[i - 1]);
- }else{
- from[i] = i - 2;
- dp[i] = dp[i - 2] + 3 * abs(a[i] - a[i - 2]);
- }
- }
- cout << dp[n] << endl;
- vector<int> v;
- int x = n;
- while(x){
- v.push_back(x);
- x = from[x];
- }
- reverse(v.begin() , v.end());
- cout << v.size() << endl;
- for(int i : v)
- cout << i << " ";
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement