easy one.
if u want maximum number of nodes and k vertices then u should have k-1 components. with only one vertices and only one should contain remaining vertex ,
like
if i take 6 vertex and have to make 4 component then i will make the 4 component in this way ,
1 vertex 1 vertex 1 vertex 3 vertex.
and now i will make the last one complete graph . then it will have maximum number of edges.
so if u have n vertices and k component then just give (k-1) component one vertex and the remaining will be (n-(k-1)) now make that bigger one a complete graph . i.e ( n-k+1) ( n-k-1+1)/2 complete graph formula . n(n-1)/2 = (n-k)(n-k+1)/2