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>
using namespace std;
#include "meetings.h"
typedef long long LL;
vector<int> h;
int N,Q;
LL Dp[5010][5010];
int findmax(int l,int r){
int M=l;
for (int i=l;i<=r;i++)
if(h[i]>h[M])M=i;
return M;
}
LL dp(int l,int r){
if(l>r)return 0;
if (Dp[l][r]>0)return Dp[l][r];
if(l==r)return Dp[l][r]=h[l];
int x=findmax(l,r);
return Dp[l][r]=min(dp(l,x-1)+h[x]*(r-x+1),dp(x+1,r)+h[x]*(x-l+1));
}
vector<LL> minimum_costs(vector<int> H,vector<int> L,vector<int> R) {
N=H.size(),Q=L.size();
h=H;
vector<LL> C;
memset(Dp,0,sizeof(Dp));
for (int q=0;q<Q;q++){
C.push_back(dp(L[q],R[q]));
}
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... |