Capitalism was an ugly solution to a real problem
Not really, though. I mean, if you want to stick to looking at the last 2000 years, we still have cities that were fed in a feudal rather than capitalist system. Not that those systems were better or more efficient mobilizing labor, but the problem you're referring to wasn't really there.
That's not to mention at least several examples in the anthropological and archaeological record of large scale societies that did not rely on what we define as capitalism to feed their people.
I think it's a pretty crazy oversimplification to say capitalism just popped up as a solution to a problem.
David Graeber has written two ~700 page anthropology books that pretty much debunk this entire line of thinking, one of them a collaboration with archaeologist David Wengrow. That latter includes an almost immediate refutation of the utopian egalitarian hunter gatherer bands that so many pop scientists love to idealize, the same fetishization that you're talking about. They're pretty rigorous about it.
You should really check them out. 'Debt: the first 5000 years' and 'The Dawn of Everything', if you want I can pop the audiobooks on google drive and DM you the link.
I literally just came off listening to both of them in the span of 2 weeks, which is why I see such a generalized statement as "Capitalism was a solution to inefficient resource distribution" as a bit silly, because no one just thought, "oh you know what we need? Capitalism! It will be the solution!"
It has an insanely long history originating from pre-coinage, debt-based societies, some of which had huge populations. They definitely rail against the "agricultural revolution > cities" line of thinking, noting that archaeological evidence across the globe for agriculture shows the whole process took something around 3000 years, during which, again, there were mega-sites (essentially cities) that relied on a mix of agrarian and hunting and gathering.
The second book is, granted, more about hierarchical structures in ancient civilizations and Debt is more about social inequality when it comes to money, but I really really suggest you check em out. Lmk if you want that google drive link, I just gotta upload em