# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1061960 | Hectorungo_18 | Roller Coaster Railroad (IOI16_railroad) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
// #define int long long
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = s.size();
vector<pair<int, int>> v(n);
for(int i = 0; i < n; i++){
v[i]={s[i], t[i]};
}
sort(v.begin(), v.end());
vector<pair<int, int>> sol;
long long int ans = 1e18+7;
do{
int ex = 1;
long long int aux = 0;
for(int i = 0; i < n; i++){
if(ex <= v[i].first){
ex = v[i].second;
continue;
}
aux+=ex-v[i].first;
ex = v[i].second;
if(aux < 0) break;
}
if(aux < 0) continue;
if(ans > aux){
ans = aux;
sol = v;
}
}
while(next_permutation(v.begin(), v.end()));
// cout << ans << endl;
// for(auto x : sol){
// cout << x.first << " " << x.second << endl;;
// }
return ans;
}
signed main() {
// ios::sync_with_stdio(false); cin.tie(nullptr);
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) << endl;
}