Graphs with prescribed numbers of k-cliques

What you are asking for is possible $f$-vectors of Clique Complexes. The Kruskal-Katona Theorem characterizes $f$-vectors of simplicial complexes; so, it applies here but is no longer a complete characterization. Your problem is open according to this paper. The linked paper and references there in contain partial results.

Edit: This answer assumes the number of $k$-cliques of $G$ is $a_k$ for $1 \leq k \leq n$ and $0$ for $k > n$. Another interpretation of the question would be that the number of $k$-cliques of $G$ is $a_k$ for $1 \leq k \leq n$ and there is no restriction on the number of $k$-cliques for $k > n$. The OP has expressed interest in both variations in the comments.


The case $n=3$ was addressed in Razborov's On the Minimal Density of Triangles in Graphs, where he used his Flag Algebra technique to provide an asymptotically tight lower bound on the number of triangles contained in a graph with a given number of vertices and edges.

Let $\rho=\frac{a_2}{\binom{a_1}{2}}$ be the density of edges in the graph. If $\rho=1-\frac{1}{t}$ for some integer $t$, then the minimum number of triangles comes from a balanced, complete $t$-partite graph. If $\rho \in (1-\frac{1}{t}, 1-\frac{1}{t+1})$, then the optimal graph ends up being a complete $(t+1)$-partite graph, with $t$ equal sized parts, and one part smaller than the rest. Optimizing over the size of the parts gives the (complicated) bound in Razborov's paper.