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 N 200009
#define ll long long
#define pii pair <ll, ll>
#define ff first
#define sz() size()
#define ss second
#define pb push_back
using namespace std;
ll n;
ll vis[N];
ll v[N];
pii p[N];
ll ans=0;
void f(int x){
if(x==n){
ll sum=0, y=1;
for(int i=0; i<n; i++){
if(y>p[v[i]].ff)
sum+=y-p[v[i]].ff;
y=p[v[i]].ss;
}
ans=min(ans, sum);
return;
}
for(int i=0; i<n; i++){
if(!vis[i]){
vis[i]=1;
v[x]=i;
f(x+1);
vis[i]=0;
}
}
}
ll plan_roller_coaster(vector<int>a, vector<int>b){
n=a.size();
for(int i=0; i<n; i++)
p[i]={a[i], b[i]};
f(0);
return ans;
}
# | 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... |