No, it doesn't. You're assuming that markets have a computational efficiency and smoothness that simply isn't there. P != NP.
Markets are a heuristic based around mediating between the interests of different parties precisely because the overall problem is computationally hard. If markets achieved the kind of optimality you're thinking, then top-down central planning would also be workable.
Sure, but the usual counterargument is that the air and water need to be made legible to the market (through private ownership or the correct externality taxes), and then everything will be perfect. While in reality that's demanding a level of computation from markets that they simply do not possess.
Markets are a heuristic based around mediating between the interests of different parties precisely because the overall problem is computationally hard. If markets achieved the kind of optimality you're thinking, then top-down central planning would also be workable.