题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6000
先求出所有衣服单独洗完的最快时间
再求出所有衣服单独烘干的最快时间
之后两个拼在一起就行了,当然是当前最慢的和当前最快的拼
#include<stdio.h>
#include<queue>
#include<functional>
using namespace std;
#define LL long long
typedef struct Res
{
LL t, id;
bool operator < (const Res &b) const
{
if(t>b.t)
return 1;
return 0;
}
}Res;
Res now;
priority_queue<Res> q;
LL a[100005], b[100005], t1[1000005], t2[1000005];
int main(void)
{
LL ans;
int T, L, n, m, i, cas;
cas = 1;
scanf("%d", &T);
while(T--)
{
scanf("%d%d%d", &L, &n, &m);
for(i=1;i<=n;i++)
scanf("%lld", &a[i]);
for(i=1;i<=m;i++)
scanf("%lld", &b[i]);
while(q.empty()==0)
q.pop();
for(i=1;i<=n;i++)
{
now.t = a[i], now.id = i;
q.push(now);
}
for(i=1;i<=L;i++)
{
now = q.top();
q.pop();
t1[i] = now.t;
now.t += a[now.id];
q.push(now);
}
while(q.empty()==0)
q.pop();
for(i=1;i<=m;i++)
{
now.t = b[i], now.id = i;
q.push(now);
}
for(i=1;i<=L;i++)
{
now = q.top();
q.pop();
t2[i] = now.t;
now.t += b[now.id];
q.push(now);
}
ans = 0;
for(i=1;i<=L;i++)
ans = max(t1[i]+t2[L-i+1], ans);
printf("Case #%d: %lld\n", cas++, ans);
}
return 0;
}