#P5242. Maximizing Single Acceptance Probability
Maximizing Single Acceptance Probability
Maximizing Single Acceptance Probability
Farmer John has launched a new cow social network that matches bulls and cows based on their shared interests. Bessie, looking for a partner for the Valentine's Barn Dance, decides to try the website. After registering, the matching algorithm gives her a list of length N (where \(1 \leq N \leq 10^6\)). Each candidate on the list (a bull) accepts her invitation with probability \(p\) (where \(0 < p < 1\)).
Bessie decides to send invitations to cows in a contiguous segment from the list. However, she wants exactly one acceptance among those she invites. Help Bessie determine the maximum probability of exactly one acceptance she can achieve by optimally choosing a contiguous segment of invitations.
The probability for a segment of length \(L\) is given by the formula:
\(f(L) = L \cdot p \cdot (1-p)^{L-1}\)
You need to find the maximum value of \(f(L)\) for some integer \(L\) where \(1 \leq L \leq N\).
inputFormat
The input consists of a single line containing an integer N and a floating point number p separated by a space.
\(1 \leq N \leq 10^6\) and \(0 < p < 1\).
outputFormat
Output a single floating point number representing the maximum probability that exactly one cow accepts Bessie's invitation. The answer will be accepted if it has an absolute or relative error of at most \(10^{-6}\).
sample
5 0.5
0.5