bzoj#P2536. [NEERC2008] Clock
[NEERC2008] Clock
Description
One famous Russian architect plans to build a new monumental construction. It will be a huge clock that indicates the time from the beginning of the universe.
The face of this clock contains hands, moving at constant speeds. They are numbered from to from the fastest to the slowest one. The fastest hand makes one revolution per minute ( seconds). Each next hand moves slower than previous, the -th hand makes one revolution when the -th hand makes revolutions.
The setting mechanism of this clock is very simple. You can take a hand by the handle, located on its end, and move it in any direction. When you move the hand, slower hands are moving in proportion to their usual speeds, and faster hands are not moving. Remember that hands are huge, so setting this clock is a hard job.
Consider an example with three hands: a second hand, a minute hand, and an hour hand. Their lengths are and meters respectively. You want to set the clock from to . The easiest way to do it is to rotate the minute hand clockwise, and then move the hour hand clockwise.
The total distance you moved the handles of the hands is approximately meters.
Your task is to write a program that finds the way to set the clock that minimizes the total distance you have to move the handles.
Input
The first line of the input file contains one integer - the number of hands (). The second line contains integer numbers (). The third line contains integer numbers () - lengths of clock hands. Next two lines contain two non-negative integer numbers (one number per line): time indicated by the clock and the actual time that should be set. Both times are measured in seconds from the beginning of the universe and are less than .
Output
Print the minimal possible total distance you have to move the handles. The answer must be precise toat least digits after decimal point.
3
60 12
5 15 10
52200
453600
62.831853072