Ex 2b for Kleinberg and Tardos DP chapter.