VS and his marking scheme

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian as well.
Chef VS recently conducted an exam on the subject of Computer Science. Being biased as well as lazy, he awards marks looking at only the students' roll numbers, and not their actual answers on the exam. Students have roll numbers ranging from 1 to N, where N is the number of students in his class. For a student with roll number i, chef VS's favouritism value is given by fav_{i}.
For any two students with roll numbers next to each other, VS ensures that the one with the higher favouritism value gets strictly more than twice the marks received by the less favourite student.
The paper consisted of many problems and each problem must be graded with either the full score allotted to that problem, or zero score.
Since he does not want to get caught, VS must make sure that the number of marks awarded to any student must be expressible as a sum of maximum possible scores of problems, repeated any number of times. For example, suppose that the problems in the problem set carry marks from the set {2,5,7}. Clearly, no student can be awarded 1 mark. 7 marks may be awarded, as 7 = 2 + 5. 4 marks may also be handed out, as 4 = 2 + 2. Note that 0 marks can be awarded as well.
One of the students, Sahil, aspires to top the class, and is therefore very concerned about the marks he would get. While Sahil topping the class could have really been possible if the exam was on The Harry Potter series, his chances are rather bleak on a Computer Science test. So, he finds out the fav array by breaking into VS's office, and uses this information to find the minimum possible average of marks obtained by the class and judge the ground reality. It is certain that VS never violates the conditions mentioned in the earlier paragraphs. Print the minimum possible average. Please note that test data is generated so as to ensure that every answer is always less than 2^{52}
Input
The first line contains an integer T, denoting the number of test cases to follow.
Each test cases contains 4 lines.
The first line contains N, the number of students in the class.
The second line contains N spaceseparated integers, denoting the favouritism value for each student.
The third line contains the number of distinct marks in the set, K.
The fourth line contains K distinct numbers separated by a single space. These numbers represent the set of marks allotted to problems.
Output
Output exactly T lines, each containing the answer for the corresponding test case. Absolute error of the output should be less than 1e6. Please note that test data is generated so as to ensure that every answer is always less than 2^{52}.
Constraints
 1 ≤ T ≤ 10
 1 ≤ N ≤ 1000
 0 ≤ fav_{i} ≤ 10^{9}
 1 ≤ K ≤ 50
 1 ≤ marks allotted to a problem ≤ 50
Example:
Sample Input:
2 3 1 2 3 3 2 5 7 4 1 2 2 3 3 2 4 8
Sample Output:
2.333333 1.000000
Explanation:
Test 1:
Award 0 to student 1, 2 to student 2 and 5 to student 3.
Total score of the class = 7
Average = 7 / 3 = 2.333333
Note that 4 is also a possible total score for the class, but the condition that student 3 should get strictly more that twice the marks obtained by student 2 would have been violated.
Test 2:
Award 0 to students 1 and 3. Award 2 to students 2 and 4.
Total score of the class = 4
Average = 4 / 4 = 1.000000
Here, you must notice that, despite the fact that student 2 and 3 are favoured equally by VS, they will not necessarily get the same number of marks.
Author:  code_master01 
Tester:  rubanenko 
Editorial  http://discuss.codechef.com/problems/ANKMARKS 
Tags  code_master01, cook59, matrixexpo, mediumhard 
Date Added:  8062015 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 