Under construction

Still being built. Things may change

Archery Accuracy

Time limit7sMemory limit1024 MB

Summary
Given each archer's hit probability and the round thresholds, find the order of archers that maximizes the chance the final scoreboard is positive.
Level

Medium7 of 10

Topics
Dynamic programming, Bit manipulation, Probability
Solved
No attempts yet

Problem

You are managing an archery team for a competition. Each team member has their own fixed probability of hitting a target.

The tournament works in a series of rounds. Your team has the same number of members as there are rounds in the tournament. In each round, exactly one of your team members will participate. Each team member will participate in exactly one round. You, being the manager, get to decide in what order the team members will compete. You must submit the order to the judges before the first round starts.

The competition has a scoreboard, which shows the total number of hits minus misses. The scoreboard starts at zero at the beginning of the competition, and is cumulative. It does not get reset across rounds. A hit will increase the score by 11, while a miss will decrease it by 11. The scoreboard can go below zero.

The competition organizers have specified a list of strictly increasing positive thresholds, one per round. In each round, the chosen team member will repeatedly shoot at a target until the scoreboard has absolute value equal to the threshold. Remember that the scoreboard does not get reset across rounds.

Given that you know the thresholds as well as all of your team members' abilities, find the maximum possible probability that you will end the tournament with a positive number of hits.

Input

The first line of input contains a single integer nn (2≤n≤172 \le n \le 17), which is both the number of team members on your team and the number of rounds of the tournament.

Each of the next nn lines contains a single real number pp (0.0<p<1.00.0 < p < 1.0), the probability that the given team member hits a target. The probabilities have at most two digits after the decimal point.

Each of the next nn lines contains a single integer ss (1≤s≤1001 \le s \le 100), the threshold score for the given round. The values are strictly increasing.

Output

Output a single real number, the maximum probability that you end the tournament with a positive number of hits. The answer must be accurate to within an absolute or relative error of 10−610^{-6}.

Examples1

  1. Example 1

    Input
    4
    0.7
    0.6
    0.4
    0.3
    2
    4
    6
    8
    
    Expected output
    0.9277221