# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
297583 | eohomegrownapps | Meetings (IOI18_meetings) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
typedef long long ll;
std::vector<long long> minimum_costs(std::vector<int> H, std::vector<int> L,
std::vector<int> R) {
ll n = H.size();
vector<vector<ll>> rangemax(n,vector<ll>(n,0));
for (ll l = 0; l<n; l++){
for (ll r = l; r<n; r++){
rangemax[l][r]=max(H[r],(l==0?0:rangemax[l][r-1]));
}
}
vector<vector<ll>> rangemaxprefsum(n,vector<ll>(n,0));
for (ll r = 0; r<n; r++){
rangemaxprefsum[r][r]=rangemax[r][r];
for (ll l = r-1; l>=0; l--){
rangemaxprefsum[l][r]=rangemaxprefsum[l+1][r]+rangemax[l][r];
}
}
vector<vector<ll>> rangemaxsuffsum(n,vector<ll>(n,0));
for (ll l = n-1; l>=0; l--){
rangemaxsuffsum[l][l]=rangemax[l][l];
for (ll r = l; r<n; r++){
rangemaxsuffsum[l][r]=rangemaxsuffsum[l][r-1]+rangemax[l][r];
}
}
ll q = L.size();
vector<ll> ans(q,1e18);
for (ll i = 0; i<q; i++){
for (ll x = L[i]; x<=R[i]; x++){
ans[i]=min(ans[i],rangemaxprefsum[L[i]][x]+rangemaxsuffsum[x+1][L[i]]);
}
}
return ans;
}