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;
typedef long long ll;
#include "shortcut.h"
long long find_shortcut(int n, std::vector<int> _p, std::vector<int> d, int c)
{
vector<ll> pref;
pref.push_back(0);
for (int i = 0; i < n-1; i++){
pref.push_back(_p[i]);
pref[i+1]+=pref[i];
}
function<ll(int,int)> query;
query = [&](int l, int r)->ll{
if (l==r) return 0ll;
if (r<l) swap(l,r);
return pref[r]-pref[l];
};
ll ans = LONG_LONG_MAX;
function<void(int,int)> dene;
pair<ll,bool> pr;
dene = [&](int l, int r){
ll leftside=0;
ll rightside=0;
priority_queue<pair<ll,ll>> hoaydaaa;
ll bruh=-1;
for (int i = 0; i < n; i++){
if (i){
ll crr = 0;
while (hoaydaaa.size()>0){
ll node = hoaydaaa.top().second;
if (query(node,l)+query(i,r)+c<query(node,i)){
bruh=max(bruh,query(node,l)+d[node]);
hoaydaaa.pop();
}
else break;
}
if (hoaydaaa.size()>0){
crr=max(crr,(ll)d[i]+pref[i]+hoaydaaa.top().first);
}
if (bruh!=-1){
crr=max(crr,(ll)d[i]+bruh+c+query(i,r));
}
if (i>=r){
rightside=max(rightside,crr);
}
else {
leftside=max(leftside,crr);
}
}
hoaydaaa.push({(ll)d[i]-pref[i],i});
}
pr={max(leftside,rightside),(rightside>leftside)};
};
for (int l = 0; l < n; l++){
int ll = l, rr = n-1;
while (ll<rr){
int mid = ll+(rr-ll)/2;
dene(l,mid);
ans=min(ans,pr.first);
if (!pr.second){
rr=mid;
}
else {
ll=mid+1;
}
}
dene(l,ll);
ans=min(ans,pr.first);
}
for (int i = 0; i < n; ++i)
{
ans=max(ans,(ll)d[i]);
}
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... |
# | 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... |