#P1918. DL's Bowling Pin Knockdown
DL's Bowling Pin Knockdown
DL's Bowling Pin Knockdown
DL, a seasoned bowler, often visits the gymnasium to bowl and relieve boredom. With decades of bowling experience, his technique is flawless. One day, DL decided to try a new challenge: using his exceptional eyesight to count the number of pins arranged at various positions (about 10 meters away).
In the diagram below, each symbol (\bigcirc) represents a bowling pin:
1. (\bigcirc\ \bigcirc\ \bigcirc)
2. (\bigcirc\ \bigcirc\ \bigcirc\ \bigcirc)
3. (\bigcirc)
4. (\bigcirc\ \bigcirc)
For example, if DL intends to knock down 3 pins, he should bowl from position 1; if he wants 4 pins, he should choose position 2. Given a target number (m) and the pin counts at each available position, determine the position from which DL should bowl to knock down exactly (m) pins. If no such position exists, output -1.
inputFormat
The input consists of three parts:
1. The first line contains an integer (m), the target number of pins to knock down.
2. The second line contains an integer (n), representing the number of positions available.
3. The third line contains (n) space-separated integers, each denoting the number of pins at that position.
outputFormat
Output a single integer: the 1-indexed position DL should bowl from to knock down exactly (m) pins. If there is no such position, print -1.
sample
3
4
3 4 1 2
1