Crime at Piccadilly Circus
InterviewTime limit1sMemory limit128 MB
For each integer moment in [p, k], count how many people's inclusive intervals cover it, and report the minimum and maximum counts.
- Level
Medium5 of 10
- Topics
- Intervals, Sorting, Simulation, Brute force
- Solved
- No attempts yet
Problem
Sherlock Holmes is investigating a crime at Piccadilly Circus. He wants to know the maximum and the minimum number of people who were at the crime scene at the same time during the interval when the crime could have been committed. Scotland Yard interviewed everyone who was seen at the scene and, for each person, established the moment they arrived and the moment they left. Doctor Watson offered to process the data and work out the numbers Holmes is interested in, but he is struggling. Help him.
Time is measured in whole (integer) units. A person who arrived at moment and left at moment was present at every integer moment with . The crime could have been committed at any integer moment in the interval .
Write a program that:
- reads from standard input the time interval in which the crime could have been committed and the data gathered by Scotland Yard;
- determines, within that interval, the minimum (this can be zero) and the maximum number of people who were at the scene at the same moment;
- writes the results to standard output.
Input
The first line contains two integers and (): the earliest and the latest moment at which the crime could have been committed.
The second line contains one integer (): the number of people interviewed by Scotland Yard.
Each of the next lines contains two integers and separated by a single space (): the moment the -th person arrived at the scene and the moment they left. The -th person was present at the scene for the whole time from moment to moment inclusive.
Output
Print a single line with two integers separated by a single space: the minimum and the maximum number of people who were at the crime scene at the same moment during the interval from moment to moment inclusive.