  An optimal control problem for the continuity equation is considered. The aim
of a "controller" is to maximize the total mass within a target set at a given
time moment. The existence of optimal controls is established. For a particular
case of the problem, where an initial distribution is absolutely continuous
with smooth density and the target set has certain regularity properties, a
necessary optimality condition is derived. It is shown that for the general
problem one may construct a perturbed problem that satisfies all the
assumptions of the necessary optimality condition, and any optimal control for
the perturbed problem, is nearly optimal for the original one.
