Optimal control of a nitrogen-vacancy spin ensemble in diamond for sensing in the pulsed domain