# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
577029 | definitelynotmee | Roller Coaster Railroad (IOI16_railroad) | C++98 | 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>
#include"railroad.h"
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 1e9 + 7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const int MAXN = 1e6+1;
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = s.size();
set<int> vals;
vals.insert(0);
vals.insert(INF);
for(int i = 0; i < n; i++){
vals.insert(s[i]);
vals.insert(t[i]);
}
map<int,int> dic;
for(int i : vals)
dic[i] = dic.size();
int m = dic.rbegin()->ss;
for(int i = 0; i < n; i++){
int u = dic[s[i]], v = dic[t[i]];
delta[u]--;
delta[v]++;
g[u].push_back(v);
}
int cur = 1;
ll resp = 0;
for(int i = 0; i < m; i++){
cur+=delta[i];
if(cur < 0){
auto it = m.find(i);
auto it2 = it;
it2++;
resp+=abs(cur)*(it2->ss-it->ss);
}
}
return resp;
}