QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 32 MB مجموع النقاط: 10

#13517. Crime at Piccadilly Circus

الإحصائيات

Sherlock Holmes is investigating a crime at Piccadilly Circus. Holmes is wondering what the maximum and minimum number of people present at the crime scene simultaneously was during the time the crime could have been committed. Scotland Yard has conducted a detailed investigation, interviewed everyone seen at the crime scene, and determined the times at which they arrived and left. Dr. Watson has offered to help process the data collected by Scotland Yard and determine the numbers that interest Sherlock Holmes, but he is having trouble with it. Help him!

Task

Write a program that:

  • reads from standard input the time interval during which the crime could have been committed and the data collected by Scotland Yard,
  • determines the minimum (which could be zero, although it would be strange for no one to be at the scene of the crime when it was committed, but these are the kinds of cases Holmes and Watson deal with) and the maximum number of people who were simultaneously at the crime scene during the interval when it could have been committed,
  • prints the results to standard output.

Input

The first line of standard input contains two integers $p$ and $k$, $0 \le p \le k \le 1\,000\,000\,000$. These are, respectively, the earliest and latest moments when the crime could have been committed. The second line of standard input contains a single integer $n$, $3 \le n \le 5\,000$. This is the number of people interviewed by Scotland Yard. Each of the next $n$ lines contains two integers - line $i + 2$ contains the numbers $a_i$ and $b_i$ separated by a single space, $0 \le a_i \le b_i \le 1\,000\,000\,000$. These are, respectively, the moment the $i$-th person arrived at the crime scene and the moment they left. This means that the $i$-th person was at the crime scene for the entire time from moment $a_i$ to moment $b_i$ (inclusive).

Output

Your program should print to standard output, in the first and only line, two integers separated by a single space: the minimum and maximum number of people who were simultaneously at the crime scene during the time from moment $p$ to moment $k$ (inclusive).

Examples

Input 1

5 10
4
1 8
5 8
7 10
8 9

Output 1

1 4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.