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;
using ll = long long;
vector<ll> minimum_costs(vector<int> h, vector<int> L,
vector<int> R) {
int Q = L.size();
int n = h.size();
vector<ll> ans(Q);
vector <vector <ll>> mx(n, vector <ll> (n));
vector <vector <ll>> mx2(n, vector <ll> (n));
for (int i = 0; i < n; i++) {
mx[i][i] = h[i];
mx2[i][i] = h[i];
ll x = h[i];
for (int j = i+1; j < n; j++) {
mx[i][j] = max(x, (ll)h[j]);
x = mx[i][j];
mx[i][j] += mx[i][j-1];
}
x = h[i];
for (int j = i-1; j >= 0; j--) {
mx2[i][j] = max(x, (ll)h[j]);
mx2[i][j] += mx2[i][j+1];
}
}
for (int i = 0; i < Q; i++) {
ans[i] = 1e18;
for (int j = L[i]; j <= R[i]; j++) {
ll x = mx2[j][L[i]] + mx[j][R[i]] - h[j];
ans[i] = min(ans[i], x);
// cout << x << ' ';
}
}
// cout << '\n';
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... |