loj6035. "Yali Training 2017 Day4" Laundry

topic

"Yaleigh Training Camp 2017 Day4" Laundry

answer

Considering washing and drying separately first, the problem is reduced to a very simple greed: each time you choose the machine that takes the shortest time to process the garment, you can pile up maintenance

Consider combining it again. Clothes need to be washed and then dried, so the time to dry all the clothes must come after the time to wash the clothes

aw[i], ad[i] respectively record the time of washing and drying i clothes

t can take max

code

#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;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324534177&siteId=291194637