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 <algorithm>
#include <vector>
#include <map>
#include <utility>
#define INF 1E18
using namespace std;
int N;
long long int plan_roller_coaster(vector<int> s, vector<int> t) {
N = s.size();
if (N <= 8) {
vector<int> u;
for (int i = 0; i < 8; i++) {
u.push_back(i);
}
long long int ans = 0;
for (int i = 1; i < 8; i++) {
ans += max(0, t[u[i - 1]] - s[u[i]]);
}
while (next_permutation(u.begin(), u.end())) {
long long int temp = 0;
for (int i = 1; i < 8; i++) {
temp += max(0, t[u[i - 1]] - s[u[i]]);
}
ans = min(ans, temp);
}
return ans;
}
multimap<int, int> mymap;
for (int i = 0; i < N; i++) {
mymap.insert({s[i], t[i]});
}
int nowspeed = mymap.begin() -> second;
mymap.erase(mymap.begin());
while (!mymap.empty()) {
multimap<int, int>::iterator it = mymap.lower_bound(nowspeed);
if (it == mymap.end()) return 1;
nowspeed = it -> second;
if (mymap.lower_bound(nowspeed) == mymap.end()) {
it++;
if (it != mymap.end()) nowspeed = it -> second;
}
mymap.erase(it);
}
return 0;
}
# | 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... |