-
Notifications
You must be signed in to change notification settings - Fork 0
/
lifeguards.cpp
52 lines (39 loc) · 838 Bytes
/
lifeguards.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
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int findTimeSupported(vector<pair<int, int>>& times, pair<int, int> avoid) {
array<int, 1001> lifeguards{};
for(auto time : times) {
if(time == avoid)
continue;
int a = time.first;
int b = time.second;
for(int i = a; i < b; i++) {
lifeguards[i] = 1;
}
}
int count = 0;
for(auto x : lifeguards){
if(x == 1)
count++;
}
return count;
}
int main() {
freopen("lifeguards.in", "r", stdin);
freopen("lifeguards.out", "w", stdout);
int n;
cin >> n;
vector<pair<int, int>> times;
while(n--) {
int a, b;
cin >> a >> b;
times.push_back(make_pair(a, b));
}
int maxTime = INT_MIN;
for(auto time : times) {
maxTime = max(maxTime, findTimeSupported(times, time));
}
cout << maxTime << endl;
return 0;
}