From a profit point of view, presumably the advertising department pays for itself; in other words, the advertising department generates money for the R&D department, rather than taking money from the R&D department.
But, the advertising presumably increases the number of people taking the drug. If it's teaching patients/doctors about a valuable new drug that will make peoples' lives better, then it's a social good. But if it's persuading patients/doctors to buy the drug unnecessarily, then it's a waste.
(Also, sometimes two pharma companies have competing drugs that are basically equivalent. So they get trapped in a "Red Queen's race" where they both spend money on advertising to try to gain market share. In the end they've both spent a bunch of money on ads and ended up back where they started. For those cases, banning marketing would be a clear win.)
Edit: Also, keep in mind that "ban/regulate pharma advertising" is a different proposal than "medicare negotiation".