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"
using namespace std;
#define ll long long
ll delivery(int n, int k, int l, int p[]) {
deque<int> dq;
for(int i = 0; i < n; i ++)
if(p[i] != 0)
dq.push_back(p[i]);
ll ans = 0;
auto get = [&](ll x){return min(x, l - x);};
while(dq.size() > 0){
ll clock = dq[min((int)dq.size() - 1, k - 1)] + get(dq[min((int)dq.size() - 1, k - 1)]);
ll counterclock = l - dq[max(0, (int)dq.size() - k)] + get(dq[max(0, (int)dq.size() - k)]);
int sz = (int)dq.size();
if(clock < counterclock){
ans += clock;
for(int i = 0; i < min(sz, k); i ++)
dq.pop_front();
}
else{
ans += counterclock;
for(int i = 0; i < min(sz, k); i ++)
dq.pop_back();
}
}
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... |