#P4399. Accelerated Growth Strategy

    ID: 17645 Type: Default 1000ms 256MiB

Accelerated Growth Strategy

Accelerated Growth Strategy

Blue Mary runs a thriving internet company with excellent management but starts with no money or reputation. The company initially has n employees. Each employee can, every day, generate either x units of money or y units of reputation. They cannot generate both on the same day. In addition, Blue Mary may invest z units of money to post an advertisement on the talent market. An advertisement will recruit one new employee exactly 3 days later. However, a new advertisement can only be posted on the very day a recruitment occurs (i.e. the day when the new employee joins), so advertisement cycles cannot overlap.

Blue Mary’s goal is to obtain at least A units of money and at least B units of reputation as fast as possible. Note that if an advertisement is posted, the z units invested are deducted from the produced money. With daily production, the employees’ work can be split arbitrarily between money and reputation tasks. For an employee working a day dedicated to money production, the income is x, and for a day dedicated to reputation production, the gain is y.

The twist is that each recruited employee becomes available only after 3 days (on the recruitment day), and the earlier an employee joins the team the more working days they contribute. Specifically, if an employee is recruited on day d (via posting an ad on day d-3), then they work for T - d + 1 days if the total time elapsed is T days.

Assuming an optimal schedule, you are to determine the minimum number of days needed to achieve at least A money (after subtracting the advertisement costs) and at least B reputation.

Hint: With optimal daily allocation, the overall production can be thought of as a sum over employee‐days. For a total of S employee-days, if Sm of them are allocated for money production and the remaining S - Sm for reputation production, the totals will be Sm * x - R * z (money) and (S - Sm) * y (reputation), where R is the number of recruitments (each costing z money). The challenge is to choose when to invest in recruitment (which takes 3 days to bear fruit) so as to maximize total employee-days while balancing the cost of advertisement.

Formally, if we decide to perform R recruitment cycles in an optimal (earliest‐possible) manner, then the recruited employees join on days: 4, 7, 10, …, i.e. the ith recruited employee joins on day 3*i + 1 (for i = 1, 2, ..., R). The total available employee-days is then:

[ S = n \times T + \sum_{i=1}^{R} (T - 3i) = T,(n+R) - \frac{3R(R+1)}{2}, \quad\text{with } T \ge 3R+1. ]

To meet the goal, there must exist an allocation of employee-days such that:

[ \begin{cases} S_m \times x - R \times z \ge A, \ (S - S_m) \times y \ge B. \end{cases} ]

This is equivalent to the existence of some Sm with \(0 \le S_m \le S\) satisfying:

[ S_m \ge \frac{A + R,z}{x} \quad \text{and} \quad S - S_m \ge \frac{B}{y}. ]

Thus, a necessary and sufficient condition is:

[ S \ge \frac{A + R,z}{x} + \frac{B}{y}. ]

Your task is to compute the minimum T (in days) for which there exists an integer \(R\) (with \(0 \le R \le \lfloor (T-1)/3 \rfloor\)) satisfying the above inequality.

inputFormat

The input consists of a single line containing six integers: n x y z A B.

  • n: the initial number of employees.
  • x: money generated by an employee in one day if assigned to money production.
  • y: reputation gained by an employee in one day if assigned to reputation production.
  • z: the monetary cost to post an advertisement (which recruits one employee 3 days later).
  • A: the target amount of money required (after accounting for advertisement costs).
  • B: the target amount of reputation required.

All numbers are positive integers.

outputFormat

Output a single integer representing the minimum number of days required to achieve at least A units of money and B units of reputation.

sample

1 1 1 1 1 1
2