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 "meetings.h"
using namespace std;
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int N = H.size();
int Q = L.size();
vector<long long> ans(Q);
if (Q <= 5000 && N <= 5000) {
for (int i = 0; i < Q; i++) {
vector<long long> cost_l(R[i] - L[i] + 2), cost_r(R[i] - L[i] + 2);
stack<pair<int, int>> st;
st.emplace(2e9, R[i] - L[i] + 1);
for (int j = R[i] - L[i]; j >= 0; j--) {
while (st.top().first <= H[j + L[i]]) st.pop();
cost_r[j] = cost_r[st.top().second] + (long long)H[j + L[i]] * (st.top().second - j);
st.emplace(H[j + L[i]], j);
}
while (!st.empty()) st.pop();
st.emplace(2e9, 0);
for (int j = 0; j <= R[i] - L[i]; j++) {
while (st.top().first <= H[j + L[i]]) st.pop();
cost_l[j + 1] = cost_l[st.top().second] + (long long)H[j + L[i]] * (j + 1 - st.top().second);
st.emplace(H[j + L[i]], j + 1);
}
ans[i] = 1e18;
for (int j = 0; j <= R[i] - L[i]; j++) {
ans[i] = min(ans[i], cost_l[j + 1] + cost_r[j] - H[j + L[i]]);
}
}
}
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... |