If you think about it, profit is Revenue minus Cost. Also, Revenue must be Demand times Price. Mysteriously, you don't have a price, but your revenue is p instead of the more usual q. Hoping that p really is your demand and not a price you haven't included, I'm going to call it q, and call the price A. Then,

Just in case a picture helps...

... where straight continuous lines differentiate downwards (integrate up) with respect to x.

Spoiler:

Put dP/dx = 0 and then make x the subject in the bottom row.

_________________________________________

Don't integrate - balloontegrate!

Balloon Calculus; standard integrals, derivatives and methods

Balloon Calculus Drawing with LaTeX and Asymptote!