Sort by minimum starting point
sort ( ranges . begin ( ) , ranges . end ( ) , [ ] ( const vector < int > & a , const vector < int > & b ) { return a [ 0 ] < b [ 0 ] ; } ) ; int end = ranges [ 0 ] [ 1 ] ; for ( int i = 1 ; i < ranges . size ( ) ; i ++ ) {