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<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
vector<int> order(n);
for(int i = 0; i < n; i++) order[i] = i;
auto check = [&] () {
long long ret = 0;
for(long long cur = 0, speed = 1; cur < n; cur++) {
int i = order[cur];
ret += max(0LL, speed - s[i]);
speed = t[i];
}
return ret;
};
long long ans = 1e18;
do {
ans = min(ans, check());
} while (next_permutation(order.begin(), order.begin() + n));
return ans;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int n; cin >> n;
vector<int> s(n), t(n);
for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
cout << plan_roller_coaster(s, t);
}
#endif // ngu
# | 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... |