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"
#define ll long long
#define all(v) v.begin() , v.end()
#define sz(a) (ll)a.size()
using namespace std;
const ll INF = 1e18;
vector<long long> minimum_costs(vector<int> H, vector<int> L,vector<int> R){
ll n,q;
n=sz(H),q=sz(L);
ll ar[n+5];
for(int i=1;i<=n;i++) ar[i]=H[i-1];
ll mx[n+5][n+5];
for(int i=1;i<=n;i++){
ll hm = ar[i];
for(int j=i;j<=n;j++){
hm=max(hm,ar[j]);
mx[i][j]=hm;
}
}
ll pre[n+5][n+5];
memset(pre,0,sizeof(pre));
for(int i=1;i<=n;i++){
ll cur = 0;
for(int j=i;j<=n;j++){
cur += mx[i][j];
pre[i][j] = cur;
}
cur = 0;
for(int j=i;j>=1;j--){
cur += mx[j][i];
pre[i][j] = cur;
}
}
vector<ll> res;
for(int i=0;i<q;i++){
ll l,r;
l=L[i]+1,r=R[i]+1;
ll xd = INF;
for(int i=l;i<=r;i++){
ll curi = pre[i][l] + pre[i][r] - ar[i];
xd = min(xd, curi);
}
res.push_back(xd);
}
return res;
}
/*void _(){
int n,q;
cin >> n >> q;
int ar[n+5];
for(int i=1;i<=n;i++) cin >> ar[i];
int mx[n+5][n+5];
for(int i=1;i<=n;i++){
int hm = ar[i];
for(int j=i;j<=n;j++){
hm=max(hm,ar[j]);
mx[i][j]=hm;
}
}
int pre[n+5][n+5];
memset(pre,0,sizeof(pre));
for(int i=1;i<=n;i++){
int cur = 0;
for(int j=i;j<=n;j++){
cur += mx[i][j];
pre[i][j] = cur;
}
cur = 0;
for(int j=i;j>=1;j--){
cur += mx[j][i];
pre[i][j] = cur;
}
}
while(q--){
int l,r;
cin >> l >> r;
int res = INF;
for(int i=l;i<=r;i++){
int curi = pre[i][l] + pre[i][r] - ar[i];
res = min(res, curi);
}
cout << res << '\n';
}
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}*/
# | 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... |