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
#define pb push_back
#define mp make_pair
#define P pair<ll, ll>
using namespace std;
const int maxn = 10000100;
ll dp[maxn], n, k, l;
int arr[maxn];
long long delivery(int N, int K, int L, int p[]) {
for(int i=0;i<N;i++) {
arr[i+1] = p[i];
}
n = N; k = K; l = L;
deque<P>dq1, dq2;
dq1.pb(mp(0, 0));
dq2.pb(mp(2LL * (l - arr[1]), 0));
for(int i=1;i<=n;i++) {
// solve for prefix of size i
ll f = dq1.front().first;
ll s = dq2.front().first;
dp[i] = min(f + min(l, 2LL*arr[i]), s);
while(dq1.size() > 0 && dq1.back().first >= dp[i]) {
dq1.pop_back();
}
dq1.push_back(mp(dp[i], i));
while(dq2.size() > 0 && dq2.back().first >= dp[i] + 2LL * (l - arr[i+1])) {
dq2.pop_back();
}
dq2.push_back(mp(dp[i] + 2LL*(l-arr[i+1]), i));
// check firsts
if(dq1.front().second == i-k) dq1.pop_front();
if(dq2.front().second == i-k) dq2.pop_front();
}
return dp[n];
}
# | 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... |