Golf Bot
Time limit1sMemory limit256 MB
Count how many hole distances equal one dial distance or the sum of two dial distances.
- Level
Medium7 of 10
- Topics
- Divide and conquer, Math, Array
- Solved
- No attempts yet
Problem
Do you like golf? I hate it. I hate golf so much that I decided to build the ultimate golf robot, a robot that never misses a shot. I place it over the ball, choose the direction and the distance, and it strikes the ball across the air and into the hole. Golf will never be played again.
It did not work out that way. Standing on the green and preparing my first stroke, I noticed that the distance dial built into the robot does not carry every distance. Not everything is lost, because I get two strokes.
With the robot as it is, how many holes can I complete in two strokes or fewer?
Input
The first line has one integer , the number of different distances the Golf Bot can shoot. Each of the following lines has one integer , the distance marked at position of the dial.
The next line has one integer , the number of holes in this course. Each of the following lines has one integer , the distance from the Golf Bot to hole .
Output
Print one integer, the number of holes the Golf Bot can complete.
The Golf Bot cannot shoot past a hole on purpose and then shoot backwards. Hole therefore falls only when one dial distance equals , or when two dial distances add up to . The same distance may be chosen for both strokes.
Limits
Hint
Suppose the Golf Bot can shoot the three distances 1, 3 and 5, and the course has holes at distances 2, 4, 5, 7, 8 and 9. Four of them fall.
- The hole at distance 2 takes two strokes of 1.
- The hole at distance 4 takes one stroke of 3 and one stroke of 1, in either order.
- The hole at distance 5 takes a single stroke of 5.
- The hole at distance 8 takes one stroke of 3 and one stroke of 5.
The holes at distances 7 and 9 can never be reached.