Monkeying Around
InterviewTime limit1sMemory limit1024 MB
Each monkey has one unknown jump that makes its total displacement zero. Find the monkey whose average height over the M jumps is highest.
- Level
Easy3 of 10
- Topics
- Math, Simulation
- Solved
- No attempts yet
Problem
baby monkeys are playing in treetops. They all start from the same height, and each of them finishes where it started from. Each monkey makes jumps, and each jump is an integer showing how many centimeters higher or lower the monkey moved. For each monkey, the height of one jump is unknown and is written as zero in the input. Assuming the jumps take place after equal time intervals, find the monkey who was on the highest level on average.
Input
The first line contains (), the number of monkeys, and (), the number of jumps. Each of the following lines contains space-separated integers (). is how many centimeters higher the corresponding monkey moved with the corresponding jump, and a negative value means it moved lower. Each line contains exactly one , which marks the unknown jump.
Output
Output exactly one integer, the index of the monkey who was on the highest level on average. The monkeys are indexed in the order their data are given. When computing the average, include the common final height after the last jump, but exclude the initial height before the first jump. If several monkeys have the maximal average level, output the index of any of them.