This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <vector>
#define ll long long
#define vll vector<ll>
vll h;
const int siz = 5002;
int maxi[siz][siz];
ll q(int a,int b){
if(a>b)return 0;
int in = maxi[a][b];
return min((b-in+1)*h[in]+q(a,in-1), (in-a+1)*h[in]+q(in+1,b));
}
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
for(int hi :H)h.push_back(hi);
int Q = L.size();
std::vector<ll> ans(Q);
int N= H.size();
for(int i = 0; i < N; i++){
int m = i;
for(int j = i; j < N; j++){
if(H[j]>H[m])m=j;
maxi[i][j]=m;
}
}
for (int j = 0; j < Q; ++j) {
ans[j] = q(L[j],R[j]);
}
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... |