You are at the gym and you want to do some training. The training process is divided into one-minute segments. During each minute, you can either train or rest.
If you choose to train during a minute, it increases your pulse by trainChange. That is, if your pulse was X, it becomes X + trainChange after a minute of training. You never want your pulse to exceed maxPulse, so you can train only if X + trainChange is less than or equal to maxPulse.
If you choose to rest during a minute, it decreases your pulse by restChange. That is, if your pulse was X, it becomes X - restChange after a minute of rest. However, your pulse never falls below minPulse, so if X - restChange is less than minPulse, your pulse becomes minPulse instead of X - restChange.
Your pulse is initially minPulse. You want to train for a total of needToTrain minutes (these minutes don't need to be consecutive). Return the minimum number of minutes your complete training process will take. If you can't train for needToTrain minutes, return -1 instead.