New algorithm in the variation after projection calculations for non-yrast nuclear states