Slimming Plan
InterviewTime limit2sMemory limit512 MB
Simulate daily weight changes from the repeating D-day plan and report the day the weight reaches T, or output -1 if it never does.
- Level
Easy3 of 10
- Topics
- Simulation, Array, Implementation
- Solved
- No attempts yet
Problem
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose weight.
Chokudai made a slimming plan with a cycle of days. It is represented by integers . His weight is on day 0 of the plan, and he aims to reduce it to . If his weight on day of the plan is , it will be on day . Here is the remainder obtained by dividing by . If his weight gets less than or equal to , he stops slimming immediately.
If his slimming plan takes too many days or never ends, he should reconsider it.
Determine whether it ends, and report how many days it takes if it ends.
Input
The input consists of a single test case formatted as follows.
S T D
w0⋯wD−1
The first line consists of three integers . The second line consists of integers ( for each ).
Output
If Chokudai's slimming plan ends on the -th day, print in one line. If it never ends, print .