Editorial for LCC '24 Contest 2 J3 - Eric's Apple Orchard
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
Note that when or
, Eric's profit is non-positive. He would just make more money by not selling apples.
For this subtask, it suffices to try all values of from 1 to
, and take the first value of
that maximizes the profit.
Subtask 2
Note that Eric's revenue can be written as . By completing the square, we get
.
When is even, then the profit is simply maximized if and only if
. However, when
is odd, then the minimum value of this expression is
, attained when
. In other words, this occurs when
. Taking the smaller value, the solution is
.
Comments