From my experience as a DIY'er ... PAINT FIRST! You have less chances at having a huge ($$) mistake. One spill can require replacement of carpet or can cost hours of elbow grease scraping and/or removing paint. So, paint first and do the flooring later. That's my 2 cents.