Application of the penalty method to nonstationary approximation of an optimization problem