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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
long long delivery(int n, int k, int l, int p[]) {
vector<pair<int,int>> vec;
for(int i=0;i<n;i++){
if(vec.empty() or p[i]!=vec.back().f){
vec.push_back({p[i],1});
}
else{
auto pp=vec.back();
vec.pop_back();
vec.push_back({pp.f,pp.s+1});
}
}
int pos=-1;
int sz=(int)vec.size();
for(int i=0;i<sz;i++){
if(vec[i].f<(l+1)/2){
pos=i;
}
}
ll ans=0;
int last1=0,last2=0;
if(pos!=-1){
int cur=0;
while(cur<=pos){
int left=k;
int mx=vec[cur].f;
while(cur<=pos and left>0){
int prv=vec[cur].s;
vec[cur].s=max(0,vec[cur].s-left);
left-=(prv-vec[cur].s);
mx=vec[cur].f;
if(vec[cur].s==0) cur++;
}
last1=k-left;
ans+=2*mx;
}
}
if(pos<sz-1){
int cur=sz-1;
while(cur>pos){
int left=k;
int mn=vec[cur].f;
while(cur>pos and left>0){
int prv=vec[cur].s;
vec[cur].s=max(0,vec[cur].s-left);
left-=(prv-vec[cur].s);
mn=vec[cur].f;
if(vec[cur].s==0) cur--;
}
last2=k-left;
ans+=2*(l-mn);
}
}
if(last1+last2<=k){
ll tmp=ans;
if(pos>=0){
tmp-=2*vec[pos].f;
}
if(pos<sz-1){
tmp-=2*(l-vec[pos+1].f);
}
tmp+=l;
ans=min(ans,tmp);
}
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... |