UPC 6910 洗衣服/hdu 6000 wash

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Seeyouer/article/details/81503761

题目描述

你现在要洗L件衣服。你有n台洗衣机和m台烘干机。由于你的机器非常的小,因此你每次只能洗涤(烘干)一件衣服。
第i台洗衣机洗一件衣服需要wi分钟,第i台烘干机烘干一件衣服需要di分钟。请问把所有衣服洗干净并烘干,最少需要多少时间?假设衣服在机器间转移不需要时间,并且洗完的衣服可以过一会再烘干。

输入

输入第一行有3个整数L,n和m。第二行有n个整数w1,w2,...,wn。第三行有m个整数d1,d2,...,dm。

输出

输出一行一个整数,表示所需的最少时间。

样例输入

1 1 1
1200
34
扫描二维码关注公众号,回复: 3468893 查看本文章

样例输出

1234

L件衣服从开始洗到结束,总共花费的最短的时间是唯一的,每一次洗完的时间也是唯一的,我们把这些时间用一个优先队列记录下来(大的先出)。同理每次的烘干花费的时间也是唯一的。要想让所有衣服全都烘干完的时间最早,那就只能让越晚洗完的越快烘干完,所以就按这个次序洗+烘,求出每一件衣服的洗+烘的时间allt,所有衣服的allt的最大值即为答案。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point{
    ll ti,cost;
    friend bool operator< (point n1, point n2)
    {
        return n1.ti > n2.ti;
    }

};
priority_queue<point>q1,q2;
priority_queue<ll >q3;
priority_queue<ll, vector<ll>, greater<ll> > q4;
int main()
{
    int l,n,m;
    scanf("%d%d%d",&l,&n,&m);
    ll c;
    for(int i=0;i<n;i++){
        scanf("%lld",&c);
        q1.push({c,c});
    }
    for(int i=0;i<m;i++){
        scanf("%lld",&c);
        q2.push({c,c});
    }
    for(int i=1;i<=l;i++){
        point u=q1.top();
        q3.push(u.ti);
        q1.pop();
        q1.push({u.ti+u.cost,u.cost});
    }
    for(int i=1;i<=l;i++){
        point u=q2.top();
        q4.push(u.ti);
        q2.pop();
        q2.push({u.ti+u.cost,u.cost});
    }
    ll ans=0;
    for(int i=1;i<=l;i++){
        ans=max(ans,q3.top()+q4.top());
        q3.pop();q4.pop();
    }
    cout<<ans<<endl;
    return 0;
}

/*
2 3 2
100 10 1
10 11
*/

猜你喜欢

转载自blog.csdn.net/Seeyouer/article/details/81503761
UPC