Locally algebraic vectors in extensions and the Breuil-Mézard conjecture