The drug companies are presumably pricing optimally for profit (but not for maximum public benefit, for which the optimum price is ~0). You could calculate the net present value of the drug companies' total profits attributable to the patent, add on 10% as a bonus, and pay them off. If the welfare gains of having cheap drugs are genuinely greater than the value of the patent to the holder, this would be win/win.