The Union of k-Segments

CodeForces - 612D