#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define int long long
std::vector<long long> minimum_costs(std::vector<signed> H, std::vector<signed> L, std::vector<signed> R) {
int Q = L.size();
int n = H.size();
std::vector<long long> C(Q);
vvi dp(n, vi(n, 0));
for(int i = 0; i < n; i++)
{
dp[i][i] = H[i];
int mx = H[i];
int total = 0;
for(int k = i; k < n; k++) {
mx = max((int)H[k], mx);
total += mx;
dp[i][k] = total;
}
}
vvi dp1(n, vi(n, 0));
for(int i = 0; i < n; i++)
{
dp[i][i] = H[i];
int mx = H[i];
int total = 0;
for(int k = i; k >= 0; k--) {
mx = max((int)H[k], mx);
total += mx;
dp[i][k] = total;
}
}
auto getmax = [&](int l, int r) {
int re = 0;
for(int i = l; i < r; i++)
{
re = max(re, (int)H[i]);
}
return re;
};
for (int j = 0; j < Q; ++j) {
int best = LONG_LONG_MAX;
for(int i = L[j]; i <= R[j]; i++)
{
int score = dp[i][R[j]] + dp1[i][L[j]] - H[i];
best = min(score, best);
}
C[j] = best;
}
return C;
}
# | 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... |