#P1204. [USACO1.2] 挤牛奶 Milking Cows

[USACO1.2] 挤牛奶 Milking Cows

Description

Three farmers get up at 55 a.m. every morning and go to the barn to milk three cows.

The first farmer starts milking at 300300 seconds (counted from 55 o'clock) and continues until 10001000 seconds. The second farmer starts at 700700 seconds and ends at 12001200 seconds. The third farmer starts at 15001500 seconds and ends at 21002100 seconds.

The longest continuous time during which at least one farmer is milking is 900900 seconds (from 300300 seconds to 12001200 seconds), and the longest continuous time during which no one is milking (from the beginning of any milking to the end of all milking) is 300300 seconds (from 12001200 seconds to 15001500 seconds).

Your task is to write a program that reads a list of working times for nn farmers milking nn cows and computes the following two values (both in seconds):

  1. The longest interval during which at least one person is milking.
  2. The longest interval during which no one is milking (counted from when milking begins).

Input Format

The first line contains a positive integer nn.

The next nn lines each contain two non-negative integers l,rl, r, representing one farmer’s start time and end time.

Output Format

Output a single line with two integers separated by a single space: the two answers required by the problem.

3
300 1000
700 1200
1500 2100

900 300

Hint

Constraints
For 100%100\% of the testdata, 1n50001 \le n \le 5000, 0lr1060 \le l \le r \le 10^6.

Problem translation from NOCOW.

USACO Training Section 1.21.2.

Translated by ChatGPT 5