Prof. Woodage met a problem in his research recently. In the record from his experimental device there were several "events" with time stamps, and he wants to compare them with a group of previous records. Although the previous one was also got by the same device, its duration was longer and recorded more "events".
Mr. Woodage guesses that the record which was later recorded can be viewed as a segment of the previous one. As long as added by a time offset, they would more or less match.
Now its your chance to help him. Mr. Woodage has given you the two records, and he designs a method to evaluate how well do two records match with a time offset. Your task is tell him the best offset.
The evaluation method is as follow:
p is the evaluate function given by Mr. Woodage, in which x denotes the offset time. Sequence f reflects the time stamp lists of the new experiment while g reflects the previous ones.
It's obvious that the best offset x to match is the number that make p get its minimum. Notice that x may not an integer. What's more, you should notice that in Mr. Woodage's function, more than one events in sequence f match the same event in sequence g is permitted.
There are multiple test cases. You should read to the end.
In each test case, the first line contains two integers n (1<=n <=500) and m (n<=m <=2000). n means the stamp number of sequence f, which corresponds to the new records. And m means the stamp number of sequence g, which corresponds to the previous records.
The follows n+m lines, in each of which there is only one positive integer no more than 100000000. The first n numbers consist the sequence f, and the other m numbers consist the sequence g. You can safely assume that these two sequences are both given from small to large.
For each test case, you should output one real number, which is the best offset x, rounded to 0.001. Mr. Woodage is sure that there is only one result.
2 4 1 11 36 39 49 50 3 3 4 10 16 1 11 13
38.000 -1.667
Migrated from old NTUJ.
2009Harbin
No. | Testdata Range | Score |
---|