您的位置:首页 > 其它

USACO Section 1.1: Milking Cows

2014-03-13 14:34 501 查看
/*
ID: leetcod3
PROG: milk2
LANG: C++
*/
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <cstring>
#include <cmath>
#include <list>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <stack>

using namespace std;

ofstream fout ("milk2.out");
ifstream fin ("milk2.in");

int main() {
int N;
fin >> N;
vector<pair<int, int> > input(N);
for (int i = 0; i < N; i++) fin >> input[i].first >> input[i].second;
sort(input.begin(), input.end());
//for (int i = 0; i < input.size(); i++) cout << input[i].first << " " << input[i].second << endl;
int left = input[0].first;
int right = input[0].second;
int a = right - left;
int b = 0;
for (int i = 1; i < N; i++) {
if (input[i].first <= right) {
right = max(right, input[i].second);
a = max(a, right - left);
}
else {
b = max(b, input[i].first - right);
left = input[i].first;
right = input[i].second;
}
}
fout << a << " " << b << endl;
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: