P9761 [ROIR 2021] Two Machines (Day 1)
Background
**Translated from [ROIR 2021](http://neerc.ifmo.ru/school/archive/2020-2021.html) Day 1 T1 [ Два станка](http://neerc.ifmo.ru/school/archive/2020-2021/ru-olymp-regional-2021-day1.pdf)**。
Description
There are two machines. The first machine needs $a$ minutes to start up, and then it produces $x$ parts per minute. The second machine needs $b$ minutes to start up, and then it produces $y$ parts per minute. The two machines cannot be in the startup process at the same time.
You have a total of $k$ minutes. Find the maximum number of parts that can be produced.
Input Format
The first line contains an integer $k$.
The second line contains two integers $a, x$.
The third line contains two integers $b, y$.
Output Format
Output a single integer: the maximum number of parts that can be produced.
Explanation/Hint
[Sample Explanation]:
If you start the second machine first and then start the first machine, you can produce $3\times 15+5\times 4=65$ parts.
[Constraints]:
For all subtasks, $0\le k,a,x,b,y\le 10^9$. The final answer can be stored in `long long`.
| Subtask ID | Special Constraints | Score |
| :-: | :-: | :-: |
| $1$ | $a=x=0$ | $17$ |
| $2$ | $a=b=0$ | $14$ |
| $3$ | $a=b$ | $20$ |
| $4$ | $x=y$ | $20$ |
| $5$ | None | $29$ |
Translated by ChatGPT 5