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 "meetings.h"
#include <bits/stdc++.h>
using namespace std;
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int N = H.size(), Q = L.size();
vector<long long> A(Q);
vector<vector<long long>> cost(N, vector<long long>(N, 0));
for(int i = 0; i < N; ++i){
for(int j = i - 1, c = H[i]; j >= 0; --j){
c = max(c, H[j]);
cost[j][i] = cost[j + 1][i] + 1ll * c;
}
for(int j = i + 1, c = H[i]; j < N; ++j){
c = max(c, H[j]);
cost[i][j] = cost[i][j - 1] + 1ll * c;
}
}
for(int i = 0; i < Q; ++i){
long long ans = 1e18;
for(int j = L[i]; j <= R[i]; ++j){
long long C = cost[L[i]][j] + 1ll * H[j] + cost[j][R[i]];
ans = min(ans, C);
}
assert(ans > 0);
A[i] = ans;
}
return A;
}
# | 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... |