Max has a special vanishing pencil that helps vanish line segments on X-axis. For example , if one line segment is from (1,0) to (4,0) and another one is from (3,0) to (7,0) , Max can touch his pencil on either (3,0) or (4,0) to vanish these two lines- so only 1 try is enough.
Input :
first line gives how many line segments
next line starting points of line segments
next line ending points of line segments
Output:
how many attempts to remove all the line segments/points
Example:
4
0 2 4 -8
4 5 6 -9
Expected Ouput
2
Explanation :
On putting the pencil on 4 , first three line segments will disappear. Remaining point -8,-9 will be removed in next trial.
Can we solve it using Max heap ? What I could understand , we need to find out if two segments are intersectng or not , but could not solve it .
Can anyone please help ?