# LOJ #6035.「雅礼集训 2017 Day4」洗衣服 贪心

(随机堆的随机数是1和0轮换的话,好快啊……二叉堆比左偏树快好多啊……)

#include <cstdio>
#include <cstring>
#include <algorithm>
typedef long long LL;
const int L=1000010,N=100010;
struct Heap{
LL key[N];
int val[N],n;
inline void build(){
register int i;
std::sort(val+1,val+(n+1));
for(i=1;i<=n;++i)key[i]=val[i];
}
inline LL top(){return key[1];}
inline void update(){
key[1]+=val[1];
register int index=1,next;
while(index<=(n>>1)){
next=index<<1;
if(next<n&&key[next]>key[next|1])++next;
if(key[next]>=key[index])return;
std::swap(key[index],key[next]);
std::swap(val[index],val[next]);
index=next;
}
}
}Wash,Dry;
LL a[L],b[L];
int l;
inline void Init(){
Wash.Init(),Dry.Init();
Wash.build(),Dry.build();
}
inline void work(){
register int i;
for(i=1;i<=l;++i){
a[i]=Wash.top(),Wash.update();
b[i]=Dry.top(),Dry.update();
}
}
inline void print(){
register LL ans=0;
register int i;
for(i=1;i<=l;++i)
ans=std::max(ans,a[i]+b[l-i+1]);
printf("%lld\n",ans);
}
int main(){
Init(),work(),print();
return 0;
}

posted @ 2018-03-22 17:22  TS_Hugh  阅读(...)  评论(... 编辑 收藏