# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
333874 | nicholask | 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.
#incude "meetings.h"
#include <bits/stdc++.h>
using namespace std;
vector <long long> minimum_costs(vector <int> h,vector <int> l,vector <int> r){
int n=h.size(),q=l.size();
vector <long long> res(q);
int dist[n][n];
for (int i=0; i<n; i++){
int ma=0;
for (int j=i; j>=0; j--){
ma=max(ma,h[j]);
dist[i][j]=ma;
}
ma=0;
for (int j=i; j<n; j++){
ma=max(ma,h[j]);
dist[i][j]=ma;
}
}
int c[n][n];
for (int i=0; i<n; i++){
c[i][0]=dist[i][0];
for (int j=1; j<n; j++) c[i][j]=c[i][j-1]+dist[i][j];
}
for (int i=0; i<q; i++){
int ans=4e18;
if (!l[i]){
for (int j=l[i]; j<=r[i]; j++) ans=min(ans,c[j][r[i]]);
} else {
for (int j=l[i]; j<=r[i]; j++) ans=min(ans,c[j][r[i]]-c[j][l[i]-1]);
}
res[i]=ans;
}
return res;
}