MemSQL Start[c]UP 2.0 - Round 1
D
Washer, Dryer, Folder
Codeforces
1900
原题
← CE →
翻译中…

You have $*k*$ pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has $*n*_{1}$ washing machines, $*n*_{2}$ drying machines and $*n*_{3}$ 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}$ minutes to wash one piece of laundry in a washing machine, $*t*_{2}$ minutes to dry it in a drying machine, and $*t*_{3}$ 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*, *n*_{1}, *n*_{2}, *n*_{3}, *t*_{1}, *t*_{2}, *t*_{3}$ $(1 ≤ *k* ≤ 10^{4}; 1 ≤ *n*_{1}, *n*_{2}, *n*_{3}, *t*_{1}, *t*_{2}, *t*_{3} ≤ 1000)$.

翻译中…

Output

翻译中…

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

翻译中…

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.

翻译中…

样例

Input #1
1 1 1 1 5 5 5
Output #1
15
InputCopy OutputCopy
Input #2
8 4 3 2 10 5 2
Output #2
32
InputCopy OutputCopy
题目信息
题号
452D
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。