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
long long delivery(int N, int K, int L, int p[]) {
//vector<ll> p(N);
vector<ll> left(N);
for(int i =0; i<N;i++)
{
left[i] = 2 * p[i];
if(i - K>= 0)
left[i] += left[i - K];
//cout << "LEFT "<<p[i]<<": "<<left[i]<<endl;
}
vector<ll> right(N);
for(int i =N - 1; i>=0;i--)
{
right[i] = 2 * (L - p[i] );
if(i + K <N)
right[i] += right[i +K];
//cout << "RIGHT "<<p[i]<<": "<<right[i]<<endl;
}
ll ans = min(left[N - 1], right[0]);
for(int i = 1; i<N ; i++){
ll posans = left[i - 1] + right[i];
ans = min(ans, posans);
}
for(int i = 0; i<N ; i++){
ll posans = L;
if(i > 0)
posans +=left[i - 1];
if (i +K < N)
posans +=right[i + K];
ans = min(ans, posans);
}
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... |