1. 程式人生 > >6000 Wash——思維

6000 Wash——思維

首先優先佇列處理每件衣服最早洗完的時間

然後按照最晚洗完的衣服用最快的烘乾機的原則貪心

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long LL;
int T, L, N, M;
LL W[maxn], D[maxn], finish[maxn*10], ans;
struct Node {
    int id; LL t;
    Node(int x = 0, LL y = 0) : id(x), t(y){}
    bool operator < (const Node &rhs) const { return t > rhs.t; }
}node;
priority_queue<Node> que;
int main() {
    scanf("%d", &T);
    for (int ks = 1; ks <= T; ks++) {
        scanf("%d%d%d", &L, &N, &M);
        for (int i = 1; i <= N; i++) scanf("%lld", &W[i]);
        for (int i = 1; i <= M; i++) scanf("%lld", &D[i]);
        ans = 0;
        while (!que.empty()) que.pop();
        for (int i = 1; i <= N; i++) que.push(Node(i, W[i]));
        for (int i = 1; i <= L; i++) {
            node = que.top(); que.pop();
            finish[i] = node.t;
            que.push(Node(node.id, node.t+W[node.id]));
        }
        while (!que.empty()) que.pop();
        for (int i = 1; i <= M; i++) que.push(Node(i, D[i]));
        for (int i = L; i >= 1; i--) {
            node = que.top(); que.pop();
            ans = max(ans, finish[i]+node.t);
            que.push(Node(node.id, node.t+D[node.id]));
        }
        printf("Case #%d: %lld\n", ks, ans);
    }
    return 0;
}