Optimal control of impulsive systems with nonlocal boundary conditions