A Pleasant Homework Life
Time limit2sMemory limit512 MB
Assignments are worked in cyclic order, skipping every M-th day as a rest day, and each needs Xi work days; find which assignment finishes first.
- Level
Medium5 of 10
- Topics
- Math, Binary search, Implementation, Simulation
- Solved
- No attempts yet
Problem
The professors of the computer science department hand out their assignments around the same time to make the students happy.
Taeho, who has filled his semester with majors, is being bombarded by the professors' assignments and cannot collect himself.
Each assignment is finished after working on it for days. However, Taeho gets bored early if he works on the same subject's assignment two days in a row. So he decided to work on a different subject's assignment every day. If he has assignments to do, he works on the first assignment on day , the second on day , ..., the -th on day , then goes back to the first assignment on day , and repeats.
But working on assignments without a break could kill him from overwork, so he repeats working for days and resting on day . If an assignment is due on a rest day, he does not push it to the next day; he skips it entirely.
For example, suppose there are assignments and he rests once every days. On day he does assignment , on day assignment , and on day assignment . On day he should do assignment , but since it is a rest day he skips it. Instead, on day he does assignment , not assignment .
Taeho, satisfied that he made a pleasant plan, became curious about when he would finish the assignments.
Given the days needed to complete each assignment and the rest day information, find the assignment that finishes first.
Input
The first line gives and . (, )
The second line gives , , ..., separated by spaces. ()
Output
Print the number of the assignment Taeho finishes first.