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>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int N = 200005;
struct ban
{
int s, t;
};
int n;
ban a[N];
bool operator<(const ban& a, const ban& b)
{
if (a.s < b.s)
return true;
if (a.s > b.s)
return false;
return a.t < b.t;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t)
{
n = sz(s);
for (int i = 1; i <= n; ++i)
{
a[i].s = s[i - 1];
a[i].t = t[i - 1];
}
sort(a + 1, a + n + 1);
ll ans = 0;
for (int i = 1; i < n; ++i)
{
ans += max(0, a[i].t - a[i + 1].s);
}
do
{
ll yans = 0;
for (int i = 1; i < n; ++i)
{
yans += max(0, a[i].t - a[i + 1].s);
}
ans = min(ans, yans);
} while (next_permutation(a + 1, a + n + 1));
return ans;
}
# | 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... |