The key to good dental health is NOT brushing hard. You should only use a soft brush. Brushing 3 times a day is very good but the actual brushing part should not last longer than a minute but then you should let the toothpaste sit on your teeth for 3-4 minutes before rinsing. Brushing your teeth should never be rushed or vigorous. Your gums are delicate and brushing too hard will damage tooth enamel. THis is all particularly important if you are a smoker. My dentist tells me that if people give the toothpaste enough time to do it's job then cavities are greatly reduced. I have had many good check-ups ever since he gave me this advice. You really need to let the toothpaste sit on your teeth for awhile.
They hurt because you're brushing them more, that will stop! Also, you might be brushing too hard! Make sure you have a soft bristle brush & use a light touch! As for the cavities, you didn't know they were there, you need a dentist for that!