Editorial for CCO '25 P1 - Asteroid Mining
Submitting an official solution before solving the problem yourself is a bannable offence.
Editor's note: This editorial has been adapted from https://atcoder.jp/contests/arc201/editorial/13373.
We can assume there are infinitely many dummy mineral chunks with any integer mass and value , so we only need to consider choosing mineral chunks such that the sum of masses is exactly
.
When , we can divide both
and all mineral chunk masses by
without changing the answer. (If
is not divisible by
, we replace
with
.)
Suppose the two lowest masses are and
. When
is divisible by
, the number of mineral chunks with mass
that we choose must be divisible by
. In this case, it's clearly optimal to choose them in descending order of value. In other words, we can form groups of
mineral chunks with mass
, in descending order of value, treating each group as a single mineral chunk with mass
. By performing this operation, all masses become divisible by
, so we can divide both
and all mineral chunk masses by
without changing the answer.
When is not divisible by
, we need to choose
mineral chunks with mass
. In this case, we must choose
mineral chunks with mass
that have the maximum value, and then we can reduce this to the case where
is divisible by
.
Lastly, if all mineral chunks have mass , we can use
.
By repeating this procedure at most times,
becomes
, and the total value of the chosen mineral chunks at that point is the answer. With a proper implementation, the time complexity is
.
Comments
When I did a mock sitting of this contest, this problem was solved quickly because it literally instantly reminded me of some problem I did, which turns out to be the one in the link.