# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286322 | mohammad | 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;
#define endl "\n"
// #define int long long
typedef long long ll ;
const ll ooo = 1e18 ;
const ll oo = 2e9 ;
const double PI = acos(-1) ;
const ll M = 1e9 + 7 ;
const int N = 10000010 ;
vector<ll> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
int Q = L.size();
vector<ll> C(Q);
for (int j = 0; j < Q; ++j) {
ll ans = ooo;
int l = L[j] , r = R[j];
stack<pair<ll,ll>> q;
ll cost = 0;
vector<ll> cl(r - l + 1) , cr(r - l + 1);
for(int i = l ; i <= r ;++i){
ll w = 1 ;
while(q.size() && q.top().first <= H[i]){
cost += (ll)(H[i] - q.top().first) * q.top().second;
w += q.top().second;
q.pop();
}
q.push({cost , w});
cl[i] = cost;
cost += H[i];
}
q = stack<pair<ll,ll>>();
for(int i = r ; i >= l ;--i){
ll w = 1 ;
while(q.size() && q.top().first <= H[i]){
cost += (ll)(H[i] - q.top().first) * q.top().second;
w += q.top().second;
q.pop();
}
q.push({cost , w});
cr[i] = cost;
cost += H[i];
}
for(int i = l ; i <= r ; ++i) ans = min(ans , cl[i] + cr[i] + h[i]);
C[j] = ans;
}
return C;
}