Dynamic algorithms via the primal-dual method