When you're willing to devote as much of your industry as required to make nuclear weapons, you can eventually manage it.  North Korea's economic model is basically 'everything for the military, and the rest of the country gets whatever is left afterwards'.