Stampede
Time limit1sMemory limit256 MB
Count how many moving segments are ever the closest to the origin while crossing the positive y-axis.
Problem
Farmer John's cows () look like they are stampeding along the road in front of the farm, but they are really running a foot race to settle which cow is the fastest.
Seen from above, each cow is a horizontal segment of length 1, given by the coordinates of its left corner at time . For example, describes a cow that at is the segment from to . Every cow moves to the right (the direction) at a fixed rate, given as the integer amount of time she needs to move 1 unit to the right.
John is not happy that his cows are outside running instead of in the barn producing milk, and he plans to give them a stern lecture once the race ends. To work out which cows are taking part, John stands at and looks along the ray that extends in the direction. If a cow is ever the first cow visible along that ray, John sees her. A cow stays invisible if some other cow is in front of her during the whole time she crosses John's line of sight.
Compute how many cows John sees during the race.
Input
The first line contains .
Each of the next lines describes one cow with three integers , , . The cow's left endpoint is at at time , and she moves right at a constant speed of 1 unit of distance every units of time. The bounds are and , with distinct for every cow so that no collision is possible, and .
Output
Print one integer, the number of cows John sees during the entire race, counting from onward.
Hint
Time runs continuously from . John sees a cow if at some instant while she lies over the ray no cow with a smaller lies over that ray at the same instant.
A cow's segment includes both of its endpoints. She is therefore over the line of sight from the moment her right endpoint touches until the moment her left endpoint passes .