Maximum principle for optimal control problems with intermediate constraints