CF MemSQL Start[c]UP 2.0 - Round 1 D

来源:互联网 发布:淘宝买简历模板 编辑:程序博客网 时间:2024/05/19 13:06
D. Washer, Dryer, Folder
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have k pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n1 washing machines, n2drying machines and 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 t1 minutes to wash one piece of laundry in a washing machine, t2 minutes to dry it in a drying machine, and 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

The only line of the input contains seven integers: k, n1, n2, n3, t1, t2, t3 (1 ≤ k ≤ 104; 1 ≤ n1, n2, n3, t1, t2, t3 ≤ 1000).

Output

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

Sample test(s)
input
1 1 1 1 5 5 5
output
15
input
8 4 3 2 10 5 2
output
32
Note

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 0. 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 2. Similarly, you can't start washing next piece until moment 5, 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, 12 and 15 minutes respectively. The last piece of laundry will be ready after 15 + 10 + 5 + 2 = 32 minutes.


比赛做水了。。。半夜爬起来作题脑子完全转不过来。b题看错条件,c完全想不清楚,f大概是uva上一道原题,不过这题加大了数据范围,没水过。回来补这道比赛怎么也想不清的d题。三台机器每台开一个队列,记录完成一个任务后的时间,那么队首元素就是最早的能提供服务的机器的时间。对每个想要放进洗衣机的衣服,先判断后面相应时间是否都有空闲机器。有的话抛掉队首,然后入队完成这件衣服的时间。这样模拟下去就可以了。
#include<cstdio>#include<algorithm>#include<vector>#include<cstring>#include<stack>#include<iostream>#include<queue>#include<cmath>#include<string>#include<set>#include<map>using namespace std;const int maxn = 60 + 5;const int INF = 1000000000;const int Mod = 1000000000 + 7;typedef long long LL;typedef pair<int, int> P;int main(){    int k, n1, n2, n3, t1, t2, t3;    while(cin >> k >> n1 >> n2 >> n3 >> t1 >> t2 >> t3){        queue<int> q1, q2, q3;        while(n1--) q1.push(0);        while(n2--) q2.push(0);        while(n3--) q3.push(0);        int ans = 0;        while(k > 0){            int c1 = q1.front();            int c2 = q2.front()-t1;            int c3 = q3.front()-t1-t2;            //cout << ans << ' ' << c1 << ' ' << c2 << ' ' << c3 << endl;            if(ans>=c1 && ans>=c2 && ans>=c3){                q1.pop();                q1.push(ans+t1);                q2.pop();                q2.push(ans+t1+t2);                q3.pop();                q3.push(ans+t1+t2+t3);                k--;            }            else                ans = max(c1, max(c2, c3));        }        ans += t1+t2+t3;        printf("%d\n" ,ans);    }    return 0;}


0 0