R&D stays in private sector. All successful drugs are bought by the government at the cost of R&D and a sizable profit. The government, then, distributes it. Government can control the distribution and Pvt. markets can control the invention.
Government can then tie up with other govts. and allow sales of the said medicine in those countries.
It's not an ideal solution, but it has best of both capitalist and socialist ideologies.