CF452D Washer, Dryer, Folder

Title Description

You have kk pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n_{1}n1 washing machines, n_{2}n2 drying machines and n_{3}n3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a piece of laundry before it is washed, and you can't fold it before it is dried. Moreover, after a piece of laundry is washed, it needs to be immediately moved into a drying machine, and after it is dried, it needs to be immediately moved into a folding machine.

It takes t_{1}t1 minutes to wash one piece of laundry in a washing machine, t_{2}t2 minutes to dry it in a drying machine, and t_{3}t3 minutes to fold it in a folding machine. Find the smallest number of minutes that is enough to wash, dry and fold all the laundry you have.

Input Format

The only line of the input contains seven integers: k,n_{1},n_{2},n_{3},t_{1},t_{2},t_{3}k,n1,n2,n3,t1,t2,t3(1<=k<=10^{4}; 1<=n_{1},n_{2},n_{3},t_{1},t_{2},t_{3}<=1000) .

Output Format

Print one integer — smallest number of minutes to do all your laundry.

Translation of the meaning of problems

You have k pieces of dirty clothes to be washed and a washing machine n1, n2 n3 a dryer and an iron. At the same time each machine can only handle a piece of clothing, were spent t1, t2, t3 time. You must be an immediately wash the clothes drying, ironing immediately after drying is complete, we can not reverse the order can not be there in the middle of a two-stage interval.

The number of the input line 7 k, n1, n2, n3, t1, t2, t3. A digital output for the shortest time all ironed clothes.

1<=k<=10^4,1<=n,t<=10^3。

Sample input and output

Input # 1
1 1 1 1 5 5 5
Output # 1
15
Input # 2
8 4 3 2 10 5 2
Output # 2
32

Description / Tips

In the first example there's one instance of each machine, each taking 5 minutes to complete. You have only one piece of laundry, so it takes 15 minutes to process it.

In the second example you start washing first two pieces at moment 00 . If you start the third piece of laundry immediately, then by the time it is dried, there will be no folding machine available, so you have to wait, and start washing third piece at moment 22 . Similarly, you can't start washing next piece until moment 55 , since otherwise there will be no dryer available, when it is washed. Start time for each of the eight pieces of laundry is 0,0,2,5,10,10,120,0,2,5,10,10,12 and 1515 minutes respectively. The last piece of laundry will be ready after 15+10+5+2=3215+10+5+2=32 minutes.

 

With three priority queues;

Maintenance every washing machine, and when is in an idle state; (that is, when there will be a dress operation is completed);

The jump to each time;

min{q1.top(),q2.top(),q3.top()};

After then operation of the clothes put in the next step;

The garment is then waiting for the operation; if the washing machine can be placed in the corresponding, placed on;

 

#include<cstdio>
#include<queue>
using namespace std;
#define rep(i,a,n) for(register int i=a;i<=n;++i)
#define mi min(n1,min(n2,n3))
#define ma max(q1,max(q2,q3)) 
using namespace std;
deque<int>w,d,f;
int k,n1,n2,n3,t1,t2,t3,q1,q2,q3,mo;

inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-'){
            w=-1;
        }
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        s=s*10+ch-'0';
        ch=getchar();
    }
    return s*w;
}


int main()
{
    k=read();
    n1=read();
    n2=read();
    n3=read();
    t1=read();
    t2=read();
    t3=read();
    rep(i,1,mi)
    {
        w.push_back(t1);
        d.push_back(t1+t2);
        f.push_back(t1+t2+t3);
    }
    rep(i,mi+1,k)
    {
        q1=w.at(0);
        q2=d.at(0)-t1;
        q3=f.at(0)-t1-t2;
        if(w.size()<n1)
        q1=0;
        if(d.size()<n2)
        q2=0;
        if(f.size()<n3)
        q3=0;
        mo=ma;
        if(!(w.size()<n1))
        w.pop_front();
        if(!(d.size()<n2))
        d.pop_front();
        if(!(f.size()<n3))
        f.pop_front();
        w.push_back(mo+t1);
        d.push_back(mo+t1+t2);
        f.push_back(mo+t1+t2+t3);
    }
    printf("%d ",f.back());
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11669080.html