How to derive an aggregate demand function (and optimal uniform price) from two demand functions? If I have two demand functions

$P_1=100-10X_1$
and
$P_2=50-10X_2$

and $X_1=40$ and $X_2=60$ with $MC=10$

We have two consumer groups: 1 and 2, where 1 has a higher willingness to pay, and we have one single good. $X_1=40$ refers to number of customers. 

How might I derive the optimal uniform price and its aggregate demand function from this?
Let the market price for the good be $P$.

It is easy to see that a consumer from group $1$'s demand for the good is $$ X_1 = \frac{100-P}{10} $$

Similarly, a consumer from group $2$'s demand for the good is $$ X_2 = \frac{50-P}{10} $$

Total demand $Q$ is then given by $$ Q = 40X_1 + 60X_2 = 700-10P $$

This means that the market inverse demand curve (i.e. aggregate demand) is $$ P(Q) = 70 - \frac{Q}{10}$$

Suppose a single monopolist were serving this market. The monopolist's profit is $$ \Pi(Q) =P(Q) \cdot Q -MC \cdot Q $$

If we take the first-order condition (i.e. take the first derivative of $\Pi$ and set it equal to $0$), we know that the optimal quantity sold satisfies $$ 70 - \frac{Q^*}{5} = 10 $$

This means that $Q^* = 300$. We can plug this back into the market demand function to find that $P^* = 40$, which is the optimal uniform price.