Cow Dating
Time limit2sMemory limit512 MB
Given probabilities p_i, choose a contiguous interval maximizing the chance that exactly one bull accepts, and print 10^6 times that probability rounded down.
- Level
Hard8 of 10
- Topics
- Math, Two pointers, Probability, Prefix sum
- Solved
- No attempts yet
Problem
Not impressed by the lackluster dating websites currently available to cows (eHarmoony, Moosk, Plenty of Cows, and the like), Farmer John decides to launch a new cow dating site built on a proprietary matching algorithm that pairs cows and bulls according to a wide range of their mutual interests.
Searching for a partner for the Valentine's Day Barn Dance, Bessie decides to try the site. After she makes her account, FJ's algorithm gives her a list of possible matches (). Going through the list, Bessie concludes that each bull has probability () of accepting an invitation from her to the dance.
Bessie decides to send an invitation to every bull in a contiguous interval of the list. Virtuous as always, she wants exactly one partner. Help Bessie find the maximum probability of receiving exactly one accepted invitation, assuming she chooses the right interval.
Input
The first line of input contains (). Each of the remaining lines contains times , which is an integer.
In at least 25% of the test cases, it is further guaranteed that .
Output
Print times the maximum probability of receiving exactly one accepted invitation, rounded down to the nearest integer.
Notes
The maximal probability results from selecting the interval from the 2nd to the 3rd cow.
As a note, you should be somewhat careful with floating point precision when solving this problem. We advise using at least "doubles" (64-bit floating-point numbers) and not "floats" (32-bit floating point numbers).