Graph theory - the count of edges Let $G^n_k=(V,E)$ be graph with $|V|=n$ vertices and exactly $k$ connected components. 
Find 
$$\max_{G_{n,k}}|E|,$$
i.e. what is the maximum number of edges possible in such a graph?
Thank you for any hints.
 A: If a graph $G$ has $n$ vertices and $\ell \in \mathbb N_+$ components, 
then it has at most $\frac{1}{2} \cdot (n-\ell) \cdot (n-\ell+1)$ edges.
You choose $\ell \in \{2,3\}$ to get your answer. 
In detail: 
Let $m$ be the number of edges of $G$.
Consider that any upper bound for $m$ must remain valid if all components of $G$ are complete graphs. 
Assume that $H_1, H_2 \subseteqq G$ are such complete components with $|H_1| = n_{H_1} \geq n_{H_2} = |H_2|$.
If we replace these subgraphs by two complete graphs of order $n_{H_1}+1$ and $n_{H_2}-1$, respectively, 
then the total number of vertices of $G$ remains unchanged but the number of edges increases by $\left(\frac{(n_{H_1}+1)\cdot (n_{H_1}+1-1)}{2} + \frac{(n_{H_2}-1)\cdot(n_{H_2}-1-1)}{2}\right)-\left(\frac{n_{H_1}\cdot (n_{H_1}-1)}{2} + \frac{n_{H_2}\cdot(n_{H_2}-1)}{2}\right) = n_{H_1} - n_{H_2} + 1 > 0$.
So, the number of edges of $G$ will be at a maximum if there are $(\ell-1)$ isolated vertices and one component that is a complete graph with $(n-(\ell-1))$ vertices 
and $\frac{1}{2} \cdot (n-\ell) \cdot (n-\ell+1)$ edges.
