Estimates of Variation with Respect to a Set and Applications to Optimization Problems