What you say is partly correct.
Most of the cost of a medicine is research, so when new patented medicines come to market, they are usually very expensive because they have to generate profits.
Then, when the patents expire, generic drugs become available, which are very cheap because they are cheap to produce.