What is the smallest dimension $n$ such that for any finitely generated abelian groups $G_1, \dots, G_k$, I can find a closed oriented $n$-manifold $M$ with $H_i(M) \cong G_i$?
Some quick facts: you cannot do this for $n = 2k$. Take $G_i = 0$ for $i<k$; then Poincare duality and the universal coefficient theorem force that $G_k$ is free.
You can do this for $n=2k+2$. Take a 0-handle; attach 1-cells for every generator of $G_1$; attach $2$-handles to kill off the relators; attach $2$-handles for generators; etc. We get a manifold with boundary and handles up to degree $(k+1)$. Take the double. One need to be careful in seeing that this does not affect $H_{k+1}$, but it does not.
When is this optimal? This depends on whether $k$ is odd or not. For $k$ even, you cannot realize $H_i(M) = 0$ for $i<k$, $H_k(M) = \mathbb Z/n$ for $n$ odd, as the homology of a closed $(2k+1)$-manifold. To do this, use the torsion linking form: it's a nonsingular bilinear form $\ell: H_k(M) \otimes H_k(M) \to \mathbb Q/\mathbb Z$. When $k$ is even it's antilinear. If $H_k(M) = \mathbb Z/n$, then $\ell(1,1) = -\ell(-1,1) = \ell(1,-1) = \ell(1,n-1)$; but we also see from that same derivation that $2\ell(1,1) = 0$; but for some $j$, $n-1 = 2j$, so $2j\ell(1,1) = \ell(1,n-1) = 0$. From this and bilinearity you see that $\ell$ is identically zero. This is not possible.
For $k$ odd, this is not optimal. You can realize a sequence $G_1, \dots, G_{2m+1}$ as the homology of a $(4m+3)$-manifold. Let's do each of these separately: construct a manifold with $G_i = \mathbb Z/r$ ($r$ any integer), and $G_j = 0$ for $i \neq j \leq 2m+1$. For $i<2m+1$ you can do the same handlebody construction. For $i=2m+1$ this is trickier. For $r=0$ this is easy: just take $S^{2m+1} \times S^{2m+2}$. We have to work harder to get the torsion.
To do this, take the plumbing of the tangent bundles of $(k+1)$-spheres according to the graph $A_{r-1}$ (the path graph on $r-1$ vertices). Because the determinant of this graph's adjacency matrix (with $2$s on the diagonal) is $r$, the boundary of this plumbing has $H_k = \mathbb Z/r$ and all lower homology zero. For me to explain plumbing in this short space would do you a disservice. I suggest looking at Bredon's book "Geometry and Topology": he has the construction in a short chapter there with a clear explanation of the cited facts. The important question to answer is "why did we need $k$ odd"? And that's because the adjacency matrix of the plumbing graph is different depending on whether the dimensions of the spheres involved (here $k+1$) are odd or even - in one case it's skew-symmetric, in another it's symmetric.