Cow Jog
Time limit1sMemory limit256 MB
Cows start in fixed order with fixed speeds, and you assign the fewest lanes so no two cows in one lane ever meet by time T.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Binary search, Greedy
- Solved
- No attempts yet
Problem
Farmer John's cows are jogging along an infinite track. Cow starts at position and runs in the same direction at a constant speed of per minute. All starting positions are distinct.
The track is divided into lanes, so cows in different lanes may move past each other. No two cows in the same lane may ever occupy the same position. Farmer John does not want any cow to change lanes or adjust its speed.
The cows run for minutes. Find the minimum number of lanes he needs. Times from to count, including time itself.
Input
The first line contains the number of cows and the running time . (, )
Each of the next lines contains the starting position and the speed of one cow. is a nonnegative integer at most , and is a positive integer at most . All starting positions are distinct and are given in increasing order.
Output
Print one line with the minimum number of lanes needed so that no two cows in the same lane ever occupy the same position up to time .