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>
#define pb push_back
//#define int long long
using namespace std;
#include "meetings.h"
const long long inf = 1e17;
//#include "meetings.h"
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
int n = H.size();
vector<vector<int> > mx(n, vector<int>(n));
for(int i = 0; i < n; i++){
mx[i][i] = H[i];
}
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
mx[i][j] = max(mx[i][j-1], H[j]);
}
}
vector<vector<long long> > pre(n, vector<long long>(n)), suf(n, vector<long long>(n));
for(int i = 0; i < n; i++){
pre[i][i] = H[i];
suf[i][i] = H[i];
}
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
pre[i][j] = pre[i][j-1] + mx[i][j];
}
}
for(int i = n-1; i >= 0; i--){
for(int j = i+1; j < n; j++){
suf[i][j] = suf[i+1][j] + mx[i][j];
}
}
int Q = L.size();
vector<long long> C(Q);
for (int j = 0; j < Q; ++j) {
long long ans = inf;
for(int i = L[j]; i <= R[j]; i++){
ans = min(ans, suf[L[j]][i] + pre[i][R[j]] - H[i]);
}
C[j] = ans;
}
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... |