cses

My solution for the coding challenges of cses.fi
git clone https://git.tronto.net/cses
Download | Log | Files | Refs | README

movie_festival_1629.cpp (393B)


      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 }