Carousel greedy: A generalized greedy algorithm with applications in optimization