#P1204. [USACO1.2] 挤牛奶 Milking Cows
[USACO1.2] 挤牛奶 Milking Cows
Description
Three farmers get up at a.m. every morning and go to the barn to milk three cows.
The first farmer starts milking at seconds (counted from o'clock) and continues until seconds. The second farmer starts at seconds and ends at seconds. The third farmer starts at seconds and ends at seconds.
The longest continuous time during which at least one farmer is milking is seconds (from seconds to 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 seconds (from seconds to seconds).
Your task is to write a program that reads a list of working times for farmers milking cows and computes the following two values (both in seconds):
- The longest interval during which at least one person is milking.
- The longest interval during which no one is milking (counted from when milking begins).
Input Format
The first line contains a positive integer .
The next lines each contain two non-negative integers , 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 of the testdata, , .
Problem translation from NOCOW.
USACO Training Section .
Translated by ChatGPT 5
京公网安备 11011102002149号