Maximise conditional probability of urns I have two urns, urn $1$ contains $k$ white balls and $l$ red balls, urn $2$ contains $n - k$ white balls and $n -l$ red balls. I have the total probability 
$ P($ "white ball is drawn" $) = \frac{k}{k + l} \frac{1}{2} + \frac{n - k}{2n - (k + l)} \frac{1}{2}$
and I would like to find $k$ and $l$ such that this probability is maximal. How can I do that? I tried to set the derivative of $P$ with respect to $k$ zero but this gets awfully complicated. Is there a better way to do this? Many thanks for your help!
 A: If you set $m = k+l$, then the probability of selecting a white ball can be expressed as
$$
P_w = \frac{k}{2m} + \frac{n-k}{2(2n-m)} = \frac{k(2n-m) + (n-k)m}{2m(2n-m)} = \frac{2k(n-m) + nm}{2m(2n-m)}.
$$
This is invariant under $(k,m)\rightarrow(n-k,2n-m)$ (which just exchanges the urns), so we can assume $m \le n$ with no loss of generality.  If $m=n$, we have $P_w = 1/2$.  For $m<n$, the probability is clearly maximized by taking $k$ as large as possible, which is $k=m$ (so $l=0$).  In that case,
$$
P_w = \frac{2m(n-m) + nm}{2m(2n-m)} = \frac{3n-2m}{4n-2m} = \frac{3}{4} - \frac{m}{4(2n-m)}.
$$
This is a decreasing function of $m$, so $m$ should be taken as small as possible, which is $m=1$, in which case
$$
P_w = \frac{3}{4} - \frac{1}{4(2n-1)}.
$$
This is at least $1/2$ for all $n\ge 1$, so the answer $(k,l)=(1,0)$ always gives the best odds of drawing a white ball... probability $P=1$ if the left urn is picked, and just under $P=1/2$ if the right urn is picked, for an overall probability of just under $3/4$.
A: Hint: First try with the same number of black and white balls, as it will lead you to the solution in the more general case.  Note that if you have the same number of balls in each urn, the probability is 1/2 regardless of the distribution.  So to get the probability away from 1/2 it needs to be unbalanced.  Also if each urn is equally split, the probability will be 1/2 regardless of how many balls are in each urn.  So imagine transferring a black ball from one urn to the other and see what it does to the probability.  There is a solution that is easy to convince yourself is optimal once you see it.
A: Hint: change variables. 
Call $b_1 = l_1 + k_1 $ the balls in urn 1, $b_2 = l_2 + k_2 $ the balls in urn 2.
We may assume  $l_1 , l_2$ are fixed, and that $b_1,b_2$ are our variables, subject to the restriction $b_1 + b_2 = 2n$
You want then to maximize
$\displaystyle \frac{b_1-l_1}{b_1}\frac{1}{2} +\frac{b_2-l_2}{b_2}\frac{1}{2}$ 
which is the same that minimize  
$\displaystyle g(b_1,b_2) = \frac{l_1}{b_1} + \frac{l_2}{b_2}$ 
(with the restriction $b_1 + b_2 = 2n$)
From this, you can continue (Lagrange multipliers or whatever).
FYI, I get (assuming real values) 
$\displaystyle \frac{b_1^2}{l_1} = \frac{b_2^2}{l_2}$
which leds to 
$\displaystyle k_1 = \frac{2n}{1+\sqrt{l_2/l_1}}-l_1$
