Business#517

Business (Editorial)

Note that after days, the amounts of cash in the machines will loop, so it is only necessary to find the maximum among the first days.

For subtask 1, the maximum will be either after the first or the second day, so we can simply print the maximum between and .

For subtask 2, it is sufficient to simulate the process for the first days and update the maximum. Complexity: O(n \cdot x).

For subtask 3, note that if none of the machines get emptied, the cash increases linearly. The machines will be emptied at most times, so we can determine those points of time and only simulate the process for those time points. Complexity: O(n^2).

For subtask 4, we can simulate the process for each of the days; however, we can maintain the total cash after each day using formulas and the count of each a_i. To do this, when transitioning from day to day i+1, we first add to the total cash and then subtract for every machine which now contains dollars.

For the last subtask, we need to combine the solutions in subtask 3 and subtask 4.