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>
#define ll long long
using namespace std;
vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R)
{
int n = H.size(), q = L.size();
ll cost[n][n]; // cost from ith to jth
for(int i=0;i<n;i++)
{
cost[i][i] = H[i];
for(int k=i-1;k>=0;k--)
cost[i][k] = max(cost[i][k + 1], (ll)H[k]);
for(int k=i+1;k<n;k++)
cost[i][k] = max(cost[i][k - 1], (ll)H[k]);
for(int k=1;k<n;k++)
cost[i][k] += cost[i][k - 1];
}
vector<ll> res;
for(int i=0;i<q;i++)
{
ll ans = LLONG_MAX;
for(int k=L[i];k<=R[i];k++)
ans = min(ans, (L[i] > 0 ? cost[k][R[i]] - cost[k][L[i] - 1] : cost[k][R[i]]));
res.push_back(ans);
}
return res;
}
# | 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... |