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>
#define pb push_back
#define F first
#define S second
using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;
ll delivery(int N, int K, int L, int p[]) {
ll dp[N + 2], pd[N + 2], ans = 1e18;
vector<ll> vec = {-1};
set<pll> st;
for(int i = 0; i < N; i++) if(p[i]) vec.pb(p[i]);
dp[0] = pd[vec.size()] = 0;
st.insert({0, 0});
for(int i = 1; i < (int)vec.size(); i++){
while(st.begin()->S < i - K) st.erase(st.begin());
dp[i] = st.begin()->F + vec[i] + min(vec[i], L - vec[i]);
st.insert({dp[i], i});
}
st.clear();
st.insert({0, N + 1});
for(int i = (int)vec.size() - 1; i; i--){
while(st.begin()->S > i + K) st.erase(st.begin());
pd[i] = st.begin()->F + L - vec[i] + min(vec[i], L - vec[i]);
st.insert({pd[i], i});
}
for(ll i = 0; i < (int)vec.size(); i++) ans = min(ans, dp[i] + pd[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... |