5+12+2 = 19 .... stands for 100
B = 5 = (100/19) * 5 = 26.31%
C =12 = (100/19) * 12 = 63.15%
D= 2 = (100/19) * 2 = 10.52 %
26.31% + 63.15% + 10.52 % = 100%
But, as soon B is higher then 26.31% it can not add to the total amount no more
So
AMax = 19
MiniB = 5
MiniC = 12
MiniD = 2
B = current value for B
C = current value for C
D = current value for D
MaxB = ( (100/AMax ) * ( min(MiniB, B ))
MaxC = ( (100/AMax ) * ( min(MiniC, C ))
MaxD = ( (100/AMax ) * ( min(MiniD, D ))
So
A = MaxB + MaxC + MaxD
Example
5+12+2 = 19 .... stands for 100
How many % is 12+8+1?
Well
AMax = 19
MiniB = 5
MiniC = 12
MiniD = 2
B = 12
C = 8
D = 1
min(MiniB, B ) = 5
min(MiniC, C ) = 8
min(MiniD, D ) = 1
MaxB = ( (100/19) * ( 5 ))
MaxC = ( (100/19) * ( 8 ))
MaxD = ( (100/19) * ( 1 ))
A = ( (100/19) * ( 5 )) + ( (100/19) * ( 8 )) + ( (100/19) * ( 1 )) = 73.6842105263 %
C = ( (100/19) * ( 12 )) - ( (100/19) * ( 8 )) = 21.0526315789% short
D = ( (100/19) * ( 2 )) - ( (100/19) * ( 1 )) = 5.26315789474% short
73.6842105263% + 21.0526315789% + 5.26315789474% = 100% (with a floating point error)