-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1353.cpp
More file actions
35 lines (26 loc) · 789 Bytes
/
1353.cpp
File metadata and controls
35 lines (26 loc) · 789 Bytes
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
#include<iostream>
#include<vector>
#include<algorithm>
int maxEvents(std::vector<std::vector<int>>& events) {
std::sort(events.begin(), events.end(), [](const std::vector<int>& a, const std::vector<int>& b) {
return a[1] < b[1];
});
std::vector<bool> free(10000001, false);
int count = 0;
for(auto& event : events) {
for(int day = event[0]; day <= event[1]; ++day) {
if(!free[day]) {
free[day] = true;
count++;
break;
}
}
}
return count;
}
int main() {
std::vector<std::vector<int>> events = { {1,2}, {1,1}, {2,3}, {3,4} };
// std::vector<std::vector<int>> events = { {1,2},{2,3},{3,4} };
std::cout << maxEvents(events);
std::cin.get();
}