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>
#include "boxes.h"
#define ll long long
using namespace std;
ll delivery(int n, int k, int l, int pos[]) {
vector<ll> pref(n), suf(n);
for(int i=0; i<n; ++i) {
if(i<k) {
pref[i]=2*pos[i];
}
else {
pref[i]=pref[i-k]+2*pos[i];
}
}
for(int i=n-1; i>=0; --i) {
if(i+k>=n) {
suf[i]=2*(l-pos[i]);
}
else {
suf[i]=suf[i+k]+2*(l-pos[i]);
}
}
ll ans=min(pref[n-1], suf[0]);
for(int i=0; i<n-1; ++i) {
ans=min(ans, pref[i]+suf[i+1]);
}
ans=min(ans, pref[n-1-k]+l);
ans=min(ans, suf[k]+l);
for(int i=0; i<n-1-k; ++i) {
ans=min(ans, pref[i]+suf[i+k+1]+l);
}
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... |