2018.10.27 loj#6035. 「雅礼集训 2017 Day4」洗衣服(贪心+堆)

传送门
显然的贪心题啊。。。考试没调出来10pts滚了妙的一啊
直接分别用堆贪心出洗完第 i i i件衣服需要的最少时间和晾完第 i i i件衣服需要的最少时间。
我们设第一个算出来的数组是 a a a,第二个是 b b b,然后令 c c c数组是 b b b的一个任意排列。
于是要求 m i n min min{ m a x max max{ a 1 + c 1 , a 2 + c 2 , . . . a l + c l a_1+c_1,a_2+c_2,...a_l+c_l a1+c1,a2+c2,...al+cl}}
里面东西跟排序不等式很像啊 ,于是 a a a正序 b b b倒序加起来取最大值就行了。
代码:

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
const int N=1e6+5;
int L,n,m;
typedef long long ll;
ll a[N],b[N],t1[N],t2[N],ans=0;
int main(){
	L=read(),n=read(),m=read();
	priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > >q1,q2;
	for(int i=1,v;i<=n;++i)q1.push(make_pair(v=read(),v));
	for(int i=1,v;i<=m;++i)q2.push(make_pair(v=read(),v));
	for(int i=1;i<=L;++i){
		pair<ll,ll>tmp=q1.top();
		q1.pop();
		t1[i]=tmp.first,tmp.first+=tmp.second,q1.push(tmp);
		tmp=q2.top();
		q2.pop();
		t2[i]=tmp.first,tmp.first+=tmp.second,q2.push(tmp);
	}
	for(int i=1;i<=L;++i)ans=max(ans,t1[i]+t2[L-i+1]);
	cout<<ans;
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值