# 11262: 【原1262】Milking Cow

### 题目描述

author: shiyinchun 原OJ链接：https://acm.sjtu.edu.cn/OnlineJudge-old/problem/1262

## Sample Input

``````3
200 900
600 1300
1600 2200
``````

## Sample Output

``````1100 300
``````

## yyong119's solution

``````#include <cstdio>
#include <algorithm>
using namespace std;

struct node {
int inTime, outTime;
}a[5005];

bool cmp(const node &p, const node &q) {
return p.inTime < q.inTime;
}

int main() {

int n; scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d%d", &a[i].inTime, &a[i].outTime);
sort(a, a + n, cmp);
int maxNotEmptyTime = 0, maxEmptyTime = 0;
int currentStart = a[0].inTime, currentEnd = a[0].outTime;
for (int i = 1; i < n; ++i) {
if (a[i].inTime > currentEnd) {
maxNotEmptyTime = max(maxNotEmptyTime, currentEnd - currentStart);
maxEmptyTime = max(maxEmptyTime, a[i].inTime - currentEnd);
currentStart = a[i].inTime;
}
currentEnd = max(currentEnd, a[i].outTime);
}
maxNotEmptyTime = max(maxNotEmptyTime, currentEnd - currentStart);
printf("%d %d\n", maxNotEmptyTime, maxEmptyTime);
return 0;
}
``````