USACO Section 1.1: Milking Cows

 1 /*

 2 ID: leetcod3

 3 PROG: milk2

 4 LANG: C++

 5 */

 6 #include <iostream>

 7 #include <fstream>

 8 #include <string>

 9 #include <map>

10 #include <vector>

11 #include <set>

12 #include <algorithm>

13 #include <stdio.h>

14 #include <queue>

15 #include <cstring>

16 #include <cmath>

17 #include <list>

18 #include <cstdio>

19 #include <cstdlib>

20 #include <limits>

21 #include <stack>

22 

23 using namespace std;

24 

25 ofstream fout ("milk2.out");

26 ifstream fin ("milk2.in");

27 

28 int main() {

29     int N;

30     fin >> N;

31     vector<pair<int, int> > input(N);

32     for (int i = 0; i < N; i++) fin >> input[i].first >> input[i].second;

33     sort(input.begin(), input.end());

34     //for (int i = 0; i < input.size(); i++) cout << input[i].first << " " << input[i].second << endl;

35     int left = input[0].first;

36     int right = input[0].second;

37     int a = right - left;

38     int b = 0;

39     for (int i = 1; i < N; i++) {

40         if (input[i].first <= right) {

41             right = max(right, input[i].second);

42             a = max(a, right - left);

43         }

44         else {

45             b = max(b, input[i].first - right);

46             left = input[i].first;

47             right = input[i].second;

48         }

49     }

50     fout << a << " " << b << endl;

51     return 0;

52 }

 

你可能感兴趣的:(USACO)