If you cover the carpet properly, that's half the battle, then use a nice long edger to push down the carpet where it meets your baseboard and you can you won't get it on the carpet. That being said, if I had my choice, I would tear up the carpet, paint, then put in hardwood floors or tile.