#P1141E. Superhero Battle
Superhero Battle
No submission language available for this problem.
Description
A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly minutes. After a round ends, the next round starts immediately. This is repeated over and over again.
Each round has the same scenario. It is described by a sequence of numbers: (). The -th element means that monster's hp (hit points) changes by the value during the -th minute of each round. Formally, if before the -th minute of a round the monster's hp is , then after the -th minute it changes to .
The monster's initial hp is . It means that before the battle the monster has hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to . Print -1 if the battle continues infinitely.
The first line contains two integers and (, ). The second line contains the sequence of integers (), where is the value to change monster's hp in the -th minute of a round.
Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer such that is the first minute after which the monster is dead.
Input
The first line contains two integers and (, ). The second line contains the sequence of integers (), where is the value to change monster's hp in the -th minute of a round.
Output
Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer such that is the first minute after which the monster is dead.