Finding maximum ending time O ( n )
int maxb = * max_element ( end . begin ( ) , end . end ( ) ) ; int maxc = max ( maxa , maxb ) ; int x [ maxc + 2 ] ; memset ( x , 0 , sizeof x ) ; int cur = 0 , idx ;