Walking
InterviewTime limit1sMemory limit128 MB
Walkers start at distinct times with fixed speeds, and a later starter who arrives earlier befriends the other; find the largest group where every pair meets.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Sorting
- Solved
- No attempts yet
Problem
Consider a road of length . There are persons. The th person, for , starts walking from the beginning of the road at time and moves at a constant speed until arrival at the end of the road. No two persons start walking at the same time, and no two persons arrive at the same time.
If the th and the th person meet each other on the road, they become friends. Written as a formula, for two persons and with , they become friends if and only if .
Find the size of the largest set of persons who are all friends of each other.
Input
Your program must read from the standard input. The input consists of lines. The first line contains two integers and separated by a single space, where and . Of the next lines, line contains two integers and separated by a single space, where and .
Output
Your program must write one integer to the standard output. That integer is the size of the largest set of persons who are all friends of each other.