题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=6000
思路:
1.首先处理出对于衣服i,其最早洗完时间wash[i],可通过优先队列实现。
2.若保证总完成时间最短,则应优先烘干最后洗完的衣服,与处理最早洗完时间类似,只需按洗完时间从大到小处理,取最大值即可。
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e6+50;
struct Node
{
LL t,tot;
Node(){}
Node(LL t,LL tot):t(t),tot(tot){}
bool operator < (const Node& rhs) const
{
return rhs.tot<tot;
}
};
int l,n,m;
LL wash[maxn];
priority_queue<Node> q;
int main()
{
int t,cas=0;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&l,&n,&m);
while(!q.empty()) q.pop();
for(int i=0;i<n;i++)
{
LL x;
scanf("%lld",&x);
q.push(Node(x,x));
}
for(int i=0;i<l;i++)
{
Node t=q.top();
q.pop();
wash[i]=t.tot;
q.push(Node(t.t,t.tot+t.t));
}
while(!q.empty()) q.pop();
for(int i=0;i<m;i++)
{
LL x;
scanf("%lld",&x);
q.push(Node(x,x));
}
LL ans=0;
for(int i=l-1;i>=0;i--)
{
Node t=q.top();
q.pop();
ans=max(ans,wash[i]+t.tot);
q.push(Node(t.t,t.tot+t.t));
}
printf("Case #%d: %lld\n",++cas,ans);
}
return 0;
}