# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
299354 | Leonardo16 | 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"
#define ll long long
#define pb push_back
#define sz size
#define fst first
#define scd second
#define vl vector<ll>
#define vi vector<ll>
#define ii pair<ll,ll>
using namespace std;
vl minimum_costs(vi H, vi L,vi R) {
vl ret;
for(int i=0;i<L.sz();i++){
deque<ii>dq;
vl a1,a2;
ll sum=0;
for(int j=L[i];j<=R[i];j++){
ll x=H[j];
ii to={x,1};
while(dq.sz()&& dq[0].fst<=to.fst ){
sum-=dq[0].fst*dq[0].scd;
to.scd+=dq[0].scd;
dq.pop_front();
}
sum+=(ll)to.fst*to.scd;
dq.push_front(to);
a1.pb(sum);
}
dq.clear();
sum=0;
for(int j=R[i];j>=L[i];j--){
ll x=H[j];
ii to={x,1};
while(dq.sz()&& dq[0].fst<=to.fst ){
sum-=dq[0].fst*dq[0].scd;
to.scd+=dq[0].scd;
dq.pop_front();
}
sum+=(ll)to.fst*to.scd;
dq.push_front(to);
a2.pb(sum);
}
ll ans=1e18;
reverse(a2.begin(),a2.end());
for(int j=0;j<a1.sz();j++){
ll ai=a1[j];
if( j+1 != a1.sz() ){
ai+=a2[j+1];
}
cout<<"-> "<<ai<<endl;
ans=min(ans,ai);
}
ret.pb(ans);
// cout<<ans<<endl;
}
return ret;
}
//
//int main(){
//
// vi ans=minimum_costs({5,3,1,4,6,3,5,7,1},{0,1,3,3},{8,4,6,8});
//
//return 0;}