loj6035「雅礼集训 2017 Day4」洗衣服

题目

「雅礼集训 2017 Day4」洗衣服

题解

先单独考虑洗和烘干,问题简化为一个非常简单的贪心:每次选择处理完这件衣服总耗时最短的机器,可以堆维护

再考虑将其结合。衣服需要先洗再烘,所以烘干所有衣服的时刻必然在洗完衣服的时刻之后

aw[i], ad[i] 分别记录洗完,烘干i件衣服的耗时

1182974-20180417113201884-85601423.png

t取max就可以了

注意long long

代码

#include <bits/stdc++.h>
using namespace std;
#define N 1000005
#define ll long long

inline ll read()
{
    ll x = 0, f = 1; char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}

int l, n, m;
ll aw[N], ad[N];

struct node
{
    ll used, x;
    friend bool operator < (node a, node b)
    {
        return a.used + a.x > b.used + b.x;
    }
}w[N], d[N];

priority_queue<node> qw, qd;

int main()
{
    l = read(); n = read(); m = read();
    for(int i = 1; i <= n; i++) w[i].x = read(), qw.push(w[i]);
    for(int i = 1; i <= m; i++) d[i].x = read(), qd.push(d[i]);
    for(int i = 1; i <= l; i++)
    {
        node k = qw.top(); qw.pop();
        k.used += k.x; qw.push(k);
        aw[i] = k.used;
        
        k = qd.top(); qd.pop();
        k.used += k.x; qd.push(k);
        ad[i] = k.used;
    }
    ll ans = 0;
    for(int i = 1; i <= l; i++) ans = max(ans, aw[i] + ad[l - i + 1]);
    cout << ans;
    return 0;
}

转载于:https://www.cnblogs.com/XYZinc/p/8862632.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值