#P9761. [ROIR 2021] 两台机器 (Day 1)

[ROIR 2021] 两台机器 (Day 1)

Background

Translated from ROIR 2021 Day 1 T1 Два станка

Problem Description

There are two machines. The first machine needs aa minutes to start up, and then it produces xx parts per minute. The second machine needs bb minutes to start up, and then it produces yy parts per minute. The two machines cannot be in the startup process at the same time.

You have a total of kk minutes. Find the maximum number of parts that can be produced.

Input Format

The first line contains an integer kk.

The second line contains two integers a,xa, x.

The third line contains two integers b,yb, y.

Output Format

Output a single integer: the maximum number of parts that can be produced.

20
10 4
5 3
65

Hint

[Sample Explanation]:

If you start the second machine first and then start the first machine, you can produce 3×15+5×4=653\times 15+5\times 4=65 parts.

[Constraints]:

For all subtasks, 0k,a,x,b,y1090\le k,a,x,b,y\le 10^9. The final answer can be stored in long long.

Subtask ID Special Constraints Score
11 a=x=0a=x=0 1717
22 a=b=0a=b=0 1414
33 a=ba=b 2020
44 x=yx=y
55 None 2929

Translated by ChatGPT 5