Time limit
2s
Memory limit
16 MB
Youngsik's routine is divided into one-minute intervals. In each minute, he must choose either to exercise or to rest.
If he exercises, his pulse increases by T. That is, if his pulse was X, then after exercising for one minute it becomes X+T. Youngsik does not want his pulse to exceed M, so he may exercise only when X+T is at most M.
If he rests, his pulse decreases by R. If his pulse was X, then after resting for one minute it becomes X-R. However, the pulse must never go below m, so if X-R is less than m, the pulse becomes m instead.
Youngsik's initial pulse is m. He wants to complete N minutes of exercise. Find the minimum elapsed time needed to complete N exercise minutes. The exercise minutes do not need to be consecutive.
The first line contains five integers N, m, M, T, and R.
Print the minimum elapsed time needed to complete N minutes of exercise. If it is impossible to complete N exercise minutes, print -1.
For the first visible test case, one optimal schedule is shown below.
| Time | Action | Pulse after the action |
|---|---|---|
| 1 | Exercise | 95 |
| 2 | Exercise | 120 |
| 3 | Rest | 105 |
| 4 | Rest | 90 |
| 5 | Exercise | 115 |
| 6 | Rest | 100 |
| 7 | Rest | 85 |
| 8 | Exercise | 110 |
| 9 | Rest | 95 |
| 10 | Exercise | 120 |