This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "railroad.h"
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
long long dp[200011];
int f(int a, int b){
return max(0, a - b);
}
long long plan_roller_coaster(vector<int> s, vector<int> t) {
int n = (int) s.size();
vector<pair<int, int>> S, T;
for(int i = 0; i < n; i++){
S.push_back({s[i], i});
}
for(int i = 0; i < n; i++){
T.push_back({t[i], i});
}
sort(S.begin(), S.end());
sort(T.begin(), T.end());
fill(dp + 1, dp + n + 1, 1LL << 60);
for(int i = 0; i < n; i++){
if(S[i].se != T[i].se) dp[i + 1] = min(dp[i + 1], dp[i] + f(S[i].fi, T[i].fi));
if(i > 0 && S[i].se != T[i - 1].se && S[i - 1].se != T[i].se) dp[i + 1] = min(dp[i + 1], dp[i - 1] + f(S[i].fi, T[i - 1].fi) + f(S[i - 1].fi, T[i].fi));
}
return dp[n];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |