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"
//#include "grader.cpp"
using namespace std;
#define ll long long
const int N = 5001;
ll g[N][N][2];
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int n = H.size();
int q = L.size();
for(int i = 0 ; i < n ; i++){
int x = H[i];
g[i][i][0] = x;
for(int j = i - 1 ; j >= 0 ; j--){
x = max(x, H[j]);
g[i][j][0] = g[i][j + 1][0] + x;
}
x = H[i];
g[i][i][1] = x;
for(int j = i + 1 ; j < n ; j++){
x = max(x, H[j]);
g[i][j][1] = g[i][j - 1][1] + x;
}
}
vector <ll> ret;
for(int i = 0 ; i < q ; i++){
ll ans = 1e18;
for(int j = L[i] ; j <= R[i] ; j++){
ans = min(ans, g[j][L[i]][0] + g[j][R[i]][1] - H[j]);
}
ret.push_back(ans);
}
return ret;
}
# | 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... |