It is more statistical task than programming one.
Solution is very simple. If know mathemetical one.
Also last parameter is not really needed - in the statistics we havn't order %)
Just to help others to solve my hint - think about maximum (it is the same for all bags).
PS: If somebody asks me why I use 2/3 - I will answer - it is empiric value. I tried values in 1/2 .. 1 and local maximum somewhere in 2/3 .. 3/4 %)
PSS: YES, many years ago I knew mathematic....
Created at: Jan. 23, 2016, 3:55 p.m.; Updated at: Jan. 23, 2016, 3:55 p.m.