There are lots of beach options in and around Barcelona. The beaches north of Las Ramblas are popular (and crowded). But the girls would probably like the action in Barceloneta and along the boardwalk.
Nearby, towns like Sitges are charming and have beaches. Easy to get to by train. A day at the beach in Barcelona and another at Sitges might be a good mix.
A day to go hiking at Montserrat might be worth it if you are really into that, but I don't recommend it otherwise with your limited time.
Do spend time to see Sagrada Familia and at least one other Gaudi building (they might enjoy Casa Batllo most). Even teens are likely to be impressed with his architecture.
As for Madrid, I consider it more of a museum town, but lots of daytrips might keep everyone interested. Toledo is a great daytrip and town to explore the winding streets. Segovia is a similar, not quite as impressive town, but with an amazing Roman aqueduct.
In Madrid, the family might enjoy roast chicken at Casa Minga - open all day and easy to order (roast chicken is about it).
I agree with the others, trying to fit in San Sebastian too would really limit how much you can enjoy your time. If your flights are set into Barcelona and out of Madrid, stick with those two. They might be inspired to return some day to see more.