diff options
Diffstat (limited to '02_sorting_and_searching/movie_festival_1629.cpp')
| -rw-r--r-- | 02_sorting_and_searching/movie_festival_1629.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/02_sorting_and_searching/movie_festival_1629.cpp b/02_sorting_and_searching/movie_festival_1629.cpp new file mode 100644 index 0000000..4ec1fca --- /dev/null +++ b/02_sorting_and_searching/movie_festival_1629.cpp | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <iostream> | ||
| 3 | #include <vector> | ||
| 4 | |||
| 5 | int main() { | ||
| 6 | size_t n; | ||
| 7 | std::cin >> n; | ||
| 8 | std::vector<std::pair<int, int>> v(n); | ||
| 9 | for (size_t i = 0; i < n; i++) | ||
| 10 | std::cin >> v[i].first >> v[i].second; | ||
| 11 | std::sort(v.begin(), v.end()); | ||
| 12 | int e{-1}, s{0}; | ||
| 13 | for (auto a : v) { | ||
| 14 | if (a.first >= e) { | ||
| 15 | e = a.second; | ||
| 16 | s++; | ||
| 17 | } | ||
| 18 | e = std::min(e, a.second); | ||
| 19 | } | ||
| 20 | std::cout << s << "\n"; | ||
| 21 | } | ||
