#include #include #include #include using std::vector; struct Segment { int start, end; }; bool _sort(Segment i, Segment j) { return (i.end <= j.end); } vector optimal_points(vector &segments) { vector points; std::sort(segments.begin(), segments.end(), _sort); while (segments.size() > 0) { int v = segments.at(0).end; segments.erase(segments.begin()); points.push_back(v); for (std::vector::iterator it = segments.begin() ; it != segments.end(); ) { if (it->start <= v && it->end >= v) { segments.erase(it); } else it++; } } return points; } int main() { int n; std::cin >> n; vector segments(n); for (size_t i = 0; i < segments.size(); ++i) { std::cin >> segments[i].start >> segments[i].end; } vector points = optimal_points(segments); std::cout << points.size() << "\n"; for (size_t i = 0; i < points.size(); ++i) { std::cout << points[i] << " "; } std::cout << '\n'; }