Fishing
InterviewTime limit1sMemory limit512 MB
Each fish is an interval moving horizontally at its own speed; pick one time and one position to stab so that the maximum number of moving intervals contain that point.
- Level
Medium7 of 10
- Topics
- Geometry, Sorting, Greedy, Implementation
- Solved
- No attempts yet
Problem
Donghyun is drifting on the sea. All he has left is a single harpoon. Now that he has grown hungry, he wants to catch fish with the harpoon. Donghyun throws the harpoon straight down, as in the figure below.

fish live in the sea. For convenience, the current position of the -th fish is written as the interval [, ].
However, the fish are alive and keep moving. The speed of the -th fish is , and it always moves horizontally at a constant speed. So after seconds, the position of the -th fish is the interval [, ].
Donghyun can throw the harpoon to any position he wants at any time .
If the position where the harpoon is thrown lies inside a fish's interval, he catches that fish. That is, suppose he throws the harpoon to position after seconds. If , he has caught the -th fish.
The harpoon travels so fast that its speed can be ignored. Given that he can throw the harpoon only once, find the maximum number of fish he can catch.
Input
The first line gives the number of fish . ()
Each of the next lines gives three integers , , . (, )
Output
Print the maximum number of fish that can be caught.