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;
using ll = long long;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define BIT(mask,i) (((mask) >> (i))&1)
#define MASK(i) (1LL << (i))
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
s.push_back(1e9);
t.push_back(1);
int n = (int) s.size();
vector <ll> val;
for (ll i = 0;i < n;i ++){
val.push_back(s[i]);
val.push_back(t[i]);
}
sort(val.begin(),val.end());
val.resize(unique(val.begin(),val.end())-val.begin());
vector <ll> cnt(sz(val));
for (ll i = 0;i < n;i ++){
ll l = lower_bound(val.begin(),val.end(),s[i])-val.begin();
ll r = lower_bound(val.begin(),val.end(),t[i])-val.begin();
cnt[l]++,cnt[r]--;
}
for (ll i = 1;i < sz(val);i ++){
cnt[i] += cnt[i-1];
}
ll res = 0;
for (ll i = 0;i + 1 < sz(val);i ++){
res += max(0LL,cnt[i]) * (val[i+1]-val[i]);
}
return res;
}
# | 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... |