After more than two years of investigation, CVS Caremark Corp. agreed yesterday to pay $5 million to settle charges by the Federal Trade Commission that the company had misrepresented the price of certain prescription drugs in one of its Medicare drug plans, causing many older consumers to pay significantly higher prices than advertised.