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"
#define fi first
#define se second
#define p_b push_back
#define m_p make_pair
#define sz(x) (int)x.size()
#define pii pair <int, int>
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const ll inf = 1e18;
vector<ll> minimum_costs(vector<int> H, vector<int> l, vector<int> r) {
int n = sz(H), q = sz(l);
vector <ll> ans(q);
vector < vector <ll> > pre_calc(n, vector <ll> (n, 0));
for(int x = 0; x < n; x++){
int mx = H[x];
ll sc = 0;
for(int j = x; j < n; j++){
mx = max(mx, H[j]);
sc += mx;
pre_calc[x][j] = sc;
}
mx = H[x];
sc = 0;
for(int j = x; j >= 0; j--){
mx = max(mx, H[j]);
sc += mx;
pre_calc[x][j] = sc;
}
}
for(int i = 0; i < q; i++){
ans[i] = pre_calc[l[i]][r[i]];
for(int x = l[i] + 1; x <= r[i]; x++){
ans[i] = min(ans[i], pre_calc[x - 1][l[i]] + pre_calc[x][r[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... |