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;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
ll delivery(int N, int K, int L, int positions[]){
ll ans=0;
vector<int> pos;
for(int i=0;i<N;i++){
if(positions[i])
pos.pb(positions[i]);
}
int n=sz(pos);
vector<ll> pref(n),suff(n);
multiset<ll> window;
for(int i=0;i<n;i++){
pref[i]=1e18;
if(i<K){
pref[i]=min(2*pos[i],L);
window.insert(pref[i]);
} else{
for(int j=i-1;j>=i-K;j--){
mina(pref[i],min(2*pos[i],L)+(*window.begin()));
}
window.erase(window.find(pref[i-K]));
window.insert(pref[i]);
}
}
window.clear();
for(int i=n-1;i>=0;i--){
suff[i]=1e18;
if(n-i-1<K){
suff[i]=min(2*(L-pos[i]),L);
window.insert(suff[i]);
} else{
for(int j=i+1;j<=i+K;j++){
mina(suff[i],min(2*(L-pos[i]),L)+(*window.begin()));
}
window.erase(window.find(suff[i+K]));
window.insert(suff[i]);
}
}
ans=min(pref[n-1],suff[0]);
for(int i=0;i<n-1;i++){
mina(ans,pref[i]+suff[i+1]);
}
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... |