Bowling Ball
Time limit1sMemory limit128 MB
A ball rolls back and forth over valleys and summits while friction drains its energy at each valley, and the task is to find where it finally stops.
- Level
Medium6 of 10
- Topics
- Simulation, Math
- Solved
- No attempts yet
Problem
Neverland has many mountain ranges. A range is a chain of valleys and summits, the slope between a summit and a valley next to it is always or , and every valley and summit has an integer height. A bowling ball rolls inside a section of a range made of valleys and summits. The ball always touches the ground, so it never jumps. The mountains left of the first valley and right of the last valley are so high that the ball can never leave this section.
At time the ball starts in valley and moves toward the upper right, and its kinetic energy is . The figure below shows a range with valleys and summits, with the ball in the second valley from the left.

At time the ball has potential energy and kinetic energy , where is the mass of the ball, is the gravity constant, here , and and are the height and the speed of the ball at time . The two forms turn into each other, so the total energy stays the same while the ball moves. Valleys are the exception. Every time the ball passes the -th valley from the left, friction takes units of kinetic energy away, and if its kinetic energy at that moment is smaller than , the ball stops in that valley. There is no friction outside the valleys. The ball also loses of energy when it leaves the starting valley at time . The diameter of the ball is and its mass is .
Find the valley or the summit where the ball stops.
Input
The input holds several test cases. The first line of each test case has three space separated integers , , and (, , ). Each of the next lines has the height and the friction of the -th valley. Each of the following lines has the height of the -th summit from the left (). The -th summit lies between valley and valley and is higher than both of them. At least one is greater than , and the ball always stops after a finite time. The last line of the input is 0 0 0 0 and is not a test case.
Output
For each test case print the place where the ball stopped on one line.
- If the ball stops in valley , print
Valley: k. - If the ball stops on summit , print
Summit: k.