Those Russian Hackers
Time limit3sMemory limit256 MB
Given check-time and hacking-time distributions over k frames of length n, find the maximum probability of logging in and finishing the hack before any security check hits your session.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Probability, Divide and conquer, Math
- Solved
- No attempts yet
Statement
During the election, which lasts seconds, time is discrete. There are units of time numbered from 0 to , and every event lasts an integer number of these units.
The election is split into equal time frames: seconds 0 to , seconds to , and so on. The security program starts with the election and performs one security check in each frame. Each check lasts exactly one second. The second of each check is chosen at random: a check happens during second with probability . Checks in different frames are independent of each other.
You may log in at any second, and then you spend a random amount of hacking time. The job takes seconds with probability , independent of the security checks. You can log in only once, so after you log in you must finish the job.
The security program sends you a message each time a check finishes. You may log in right after such a message, at the next second. If a security check happens during any second when you are logged in, the election is interrupted and you fail. If you do not finish your job before the election ends, you also fail.
Find the success probability of the best strategy.
Input
The first line contains two integers and (, ), the length of each time frame and the number of security checks.
The second line contains real values (, ), the distribution of the exact second of a security check within its frame.
The third line contains real values (, ), the distribution of the hacking time.
All probabilities are given with at most six digits after the decimal point.
Output
Print the maximum probability of success. Your answer is accepted if its absolute error does not exceed .
Hints
In the first sample, there is only one security check. The best strategy is to wait until the check finishes, then log in and try to hack before time runs out. The success probability is .
In the second sample, the hacking time is always exactly four seconds. You must log in at second 1 and finish by second 4 no matter what the checks do. You succeed only if the first check happens at second 0 and the second check happens at second 5, so the probability is .
In the third sample, the best strategy is to always start hacking at second 1, which gives a success probability of 0.8.