#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_C" #include <iostream> #include <vector> #include "Mylib/IO/input_tuple_vector.cpp" #include "Mylib/Typical/interval_scheduling.cpp" namespace hl = haar_lib; int main() { int n; std::cin >> n; auto [left, right] = hl::input_tuple_vector<int, int>(n); for (auto &x : right) x += 1; auto ans = hl::interval_scheduling(left, right); std::cout << ans.size() << std::endl; return 0; }
#line 1 "test/aoj/ALDS1_15_C/main.test.cpp" #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_15_C" #include <iostream> #include <vector> #line 2 "Mylib/IO/input_tuple_vector.cpp" #include <initializer_list> #line 4 "Mylib/IO/input_tuple_vector.cpp" #include <tuple> #include <utility> #line 7 "Mylib/IO/input_tuple_vector.cpp" namespace haar_lib { template <typename T, size_t... I> void input_tuple_vector_init(T &val, int N, std::index_sequence<I...>) { (void) std::initializer_list<int>{(void(std::get<I>(val).resize(N)), 0)...}; } template <typename T, size_t... I> void input_tuple_vector_helper(T &val, int i, std::index_sequence<I...>) { (void) std::initializer_list<int>{(void(std::cin >> std::get<I>(val)[i]), 0)...}; } template <typename... Args> auto input_tuple_vector(int N) { std::tuple<std::vector<Args>...> ret; input_tuple_vector_init(ret, N, std::make_index_sequence<sizeof...(Args)>()); for (int i = 0; i < N; ++i) { input_tuple_vector_helper(ret, i, std::make_index_sequence<sizeof...(Args)>()); } return ret; } } // namespace haar_lib #line 2 "Mylib/Typical/interval_scheduling.cpp" #include <algorithm> #include <limits> #include <numeric> #line 7 "Mylib/Typical/interval_scheduling.cpp" namespace haar_lib { template <typename T> std::vector<std::pair<T, T>> interval_scheduling(const std::vector<T> &l, const std::vector<T> &r) { const int N = l.size(); std::vector<std::pair<T, T>> ret; std::vector<int> ord(N); std::iota(ord.begin(), ord.end(), 0); std::sort(ord.begin(), ord.end(), [&](int i, int j) { return r[i] < r[j]; }); auto b = std::numeric_limits<T>::lowest(); for (int i : ord) { if (l[i] >= b) { ret.emplace_back(l[i], r[i]); b = r[i]; } } return ret; } } // namespace haar_lib #line 7 "test/aoj/ALDS1_15_C/main.test.cpp" namespace hl = haar_lib; int main() { int n; std::cin >> n; auto [left, right] = hl::input_tuple_vector<int, int>(n); for (auto &x : right) x += 1; auto ans = hl::interval_scheduling(left, right); std::cout << ans.size() << std::endl; return 0; }