#C13435. Meal Distribution at School
Meal Distribution at School
Meal Distribution at School
You are given a list of students arriving and departing from a school, where each student is provided with meals on every day from the day of arrival to the day of departure, inclusive. Your task is to determine the maximum number of meals required on any given day.
Each student is represented by two integers: the arrival day and the departure day. If there are n students, then the first line of input will contain the integer n. The following n lines each contain two space-separated integers that represent the arrival and departure days for a student.
A useful hint for an efficient solution is to apply a difference array technique. More formally, if you maintain an array diff such that each student adds +1 at index a (arrival day) and -1 at index d+1 (one day after departure), the maximum number of meals on any day can be computed as:
$$ \max_{i} \left\{\sum_{j=0}^{i} diff[j]\right\} $$
Make sure to handle edge cases such as no students (i.e. when n = 0), and ensure that the input is read from stdin and the result is output to stdout.
inputFormat
The input is given via standard input (stdin) in the following format:
n arrival_1 departure_1 arrival_2 departure_2 ... arrival_n departure_n
Where n is the number of students (an integer) and each subsequent line contains two integers representing the arrival and departure days for a student.
outputFormat
The output should be a single integer, which is the maximum number of meals required on any day. The answer should be printed to standard output (stdout).
## sample3
1 4
2 5
3 6
3