Like a raging party that ends in a grinding hangover the next morning, the bidding war over Amazon's HQ2 has given way to shame and embarrassment.

New York and Virginia ultimately won the contest, by offering $1.5 billion and $573 million in tax breaks and straight cash grants, respectively. "Amazon is a billion-dollar company," tweeted Alexandria Ocasio-Cortez, the rising progressive star from New York City who's about to become a member of the House of Representatives. "The idea that it will receive hundreds of millions of dollars in tax breaks at a time when our subway is crumbling and our communities need MORE investment, not less, is extremely concerning to residents here."

Nor was this an isolated incident. State and local governments collectively fork over $70 billion to $90 billion in tax giveaways each year to attract companies. "That's more than the federal government spends on housing, education, or infrastructure," Derek Thompson noted at The Atlantic. States and cities are gutting their own ability to invest in the public, while driving up inequality and creating no net jobs in the process.

It's a terrible habit that the states need to break. But how?

Basically, this is a giant collective action problem. City and state policymakers aren't responsible for the national economy: just the jobs within their jurisdictions. In each individual instance, the winners feel like they've gained something. But collectively, everyone is left worse off.

The fix for a collective action problem is for everyone involved to set aside their short-term self-interest and agree to a common solution. Matthew Mitchell and Michael Farren compared the problem of city and state bidding wars to nuclear disarmament: On their own, the U.S. and Russia had an incentive to just keep building nuclear weapons. But by signing the START Treaty, they were able to trust each other enough to both draw down their armaments together for the collective good.

Mitchell and Farren suggest a similar compact between the states to address the HQ2 problem:

States would agree that all firms within their borders face the same tax burden. No targeted privileges or punishments. States could better prioritize the interests of the people without the leverage that these companies currently have over them. More importantly, a no-subsidies treaty would enshrine equal treatment under the law and encourage states to compete by simply offering the best tax and regulatory environments for all firms. [Matthew Mitchell and Michael Farren, The Mercatus Center]

The problem, of course, is that all 50 states — or something close to all 50 — would have to agree to the compact for it to work. The temptation would be enormous for any one state to break from the agreement and underbid its fellows, setting off the race to the bottom all over again.

The alternative to a state compact is a federal solution. Thompson laid out a few options: The national government could ban these sorts of bidding wars outright, though the constitutionality of that is suspect. Activists have also tried arguing in court that states using tax subsidies to underbid their fellows is itself unconstitutional — though those efforts keep hitting procedural roadblocks. The federal government could try punishing city and state governments that indulge in these fights by denying them federal grants and other funding.

The most straightforward federal solution, and probably the fix most likely to actually pass, might be a kind of corrective tax: The national government could impose a 100 percent tax on all corporate subsidies offered by state and city governments. (Policies like infrastructure investment or worker training that actually benefit state residents while also potentially attracting companies would not be subject to the tax.) Whatever money the latter governments offer companies, the federal government could take it right back, rendering the value of the subsidies nil. There simply wouldn't be a point to the bidding wars anymore.

None of this would be easy, of course. Bad habits are bad because they're very hard to break. But like a lot of bad habits, these bidding wars over corporate favors aren't just unseemly; they're self-destructive. States need to help themselves, or they need an intervention, before they all hit rock bottom.