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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5+5;
#define all(x) x.begin(), x.end()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
ll plan_roller_coaster(vector<int> s, vector<int> t) {
int n = (int) s.size();
vector<pii> s1(n);
set<pii> t1;
for(int i = 0; i < n; i++)
s1[i].fr = s[i], s1[i].sc = i, t1.insert({t[i],i});
sort(all(s1));
ll resp = 0;
bool esc_first = 0;
for(auto [val, i] : s1) {
if(t1.size() == 1) return resp;
auto it = t1.lower_bound({val,0});
if(it == t1.end()) {
if(esc_first) {esc_first = 1; continue; } // s1 vai ficar em 1° lugar
it--;
if((*it).sc == i) it--;
resp += val - (*it).fr;
t1.erase(it);
}
else if((*it).sc == i) {
it++;
if(it == t1.end()) it--, it--;
if(!esc_first and val > (*it).fr) { esc_first = 1; continue; }
resp += max(0, val - (*it).fr);
t1.erase(it);
}
else t1.erase(it);
}
return resp;
}
# | 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... |