Wild party

Masao’s life is hard. He lives in New York, earns good money by working
for one of the best companies in the world, and his flat is usually
crowded by beautiful models with liberal behaviors. Now Masao wants to
choose the best moment for a party, but with so many gorgeous girls in
and out of his flat, he is a bit confused. Poor Masao, indeed… can you
help him?

Given the arrival time and leaving time of every model, Masao would like
to know the maximum number of models that will be at his flat at the
same time. Additionally, he would like to know the length of that nice
event. This way, Masao could plan the wildest possible party!

Input

Input consists of several cases. Every case begins with the number of
models 1 ≤ n ≤ 10⁵ (yes, 100000, Masao is like this). Follow n pairs of
integer numbers a and ℓ, which state that a model arrives at time a and
leaves at time ℓ, with 0 ≤ a < ℓ ≤ 10⁹. A special case with n = 0 marks
the end of input.

Output

For every case, print the number of models and the length of the wildest
possible party.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T10:31:13.524Z

© Jutge.org, 2006–2026.
https://jutge.org
