On Optimization of Discontinuous Systems