ll@N,@M,@A[N][3];vectorB[N],X[M+1]; rep(i,N)B[i]={(1.0/A[i][0]-1.0/A[i][1])/(A[i][2]-1),1.0/A[i][0],1.0/A[i][1],1.0/A[i][2]}; sort(B,B+N); rep(j,M+1)X[j]={0,j<1}; rep[B](a,N){ X[M][0]+=X[M][1]*a[1]; rrep(i,M){ double p=X[i][1]*pow(1-a[3],M-i); X[M]={X[M][0]+p*a[1],X[M][1]+p}; rrep(j,i+1,M){ p=X[i][1]*pow(1-a[3],j-i)*a[3]; X[j]={X[j][0]+p*a[2],X[j][1]+p}; } X[i]={X[i][0]+X[i][1]*a[3]*a[2],X[i][1]*a[3]}; } } wt(sum[double][i,0,M+1](X[i][0]));