-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmilk2.cpp
59 lines (49 loc) · 1.33 KB
/
milk2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
ID: thc0r11
TASK: milk2
LANG: C++14
*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <limits>
bool between(int val, int start, int stop)
{
return val >= start && val <= stop;
}
int main()
{
std::ifstream in{"milk2.in"};
std::ofstream out{"milk2.out"};
int farmers;
in >> farmers;
in.ignore(100, '\n');
if (farmers == 0) {
out << "0 0\n";
return 0;
}
std::vector<std::pair<int, int>> times;
for (int i = 0; i < farmers; ++i) {
std::pair<int, int> time;
in >> time.first >> time.second;
in.ignore(100, '\n');
times.push_back(time);
}
std::sort(times.begin(), times.end(), [] (auto a, auto b) { return a.first < b.first; });
std::vector<int> chains;
int standby = 0;
int start = times[0].first, stop = times[0].second;
for (size_t i = 1; i < times.size(); ++i) {
if (between(times[i].first, start, stop))
stop = std::max(stop, times[i].second);
else {
chains.push_back(stop - start);
standby = std::max(standby, times[i].first - stop);
start = times[i].first;
stop = times[i].second;
}
}
chains.push_back(stop - start);
out << *std::max_element(chains.begin(), chains.end()) << ' ' << standby << '\n';
}