# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
292430 | zoooma13 | 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 <bits/stdc++.h>
#include "meetings.h"
#include "grader.cpp"
using namespace std;
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R){
assert(H.size() <= 5000);
vector <long long> dpL(H.size()) ,dpR(H.size()) ,ans(L.size() ,LLONG_MAX);
for(int q = 0; q < L.size(); q++){
int l = L[q] ,r = R[q];
long long cur = 0;
vector <int> mq{l-1};
for(int i=l; i<=r; i++){
while(mq.size()>1 && H[mq.back()] <= H[i]){
cur -= (mq.back()-mq[(int)mq.size()-2])*H[mq.back()];
mq.pop_back();
}
mq.push_back(i);
cur += (mq.back()-mq[(int)mq.size()-2])*H[mq.back()];
dpL[i] = cur;
}
mq = {r+1} ,cur = 0;
for(int i=r; i>=l; i--){
while(mq.size()>1 && H[mq.back()] <= H[i]){
cur -= (mq[(int)mq.size()-2]-mq.back())*H[mq.back()];
mq.pop_back();
}
mq.push_back(i);
cur += (mq[(int)mq.size()-2]-mq.back())*H[mq.back()];
dpR[i] = cur;
}
for(int i=l; i<=r; i++)
ans[q] = min(ans[q] ,dpL[i]+dpR[i]-H[i]);
}
return ans;
}