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"
using namespace std;
const int N = 5000;
long long costs[N][N];
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int n = H.size(), q = (int) L.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
costs[i][j] = 0;
}
}
for (int i = 0; i < n; i++) {
costs[i][i] = H[i];
{
int mx = H[i];
for (int j = i - 1; j >= 0; j--) {
mx = max(mx, H[j]);
costs[i][j] = costs[i][j + 1] + mx;
}
}
{
int mx = H[i];
for (int j = i + 1; j < n; j++) {
mx = max(mx, H[j]);
costs[i][j] = costs[i][j - 1] + mx;
}
}
}
vector<long long> ans(q);
for (int i = 0; i < q; i++) {
ans[i] = 1e18;
for (int k = L[i]; k <= R[i]; k++) {
ans[i] = min(ans[i], costs[k][L[i]] + costs[k][R[i]] - H[k]);
}
}
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... |