Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Rectangle{
- int length;
- int width;
- };
- bool operator<(const Rectangle& lhs, const Rectangle& rhs) {
- if (lhs.length == rhs.length) {
- return lhs.width < rhs.width;
- }
- return lhs.length < rhs.length;
- }
- int main() {
- int n;
- cin >> n;
- vector<Rectangle> rectangles(n);
- for (int i = 0; i < n; ++i) {
- int length = 0;
- int width = 0;
- cin >> length >> width;
- if (length < width) {
- swap(length, width);
- }
- rectangles[i] = {length, width};
- }
- sort(rectangles.begin(), rectangles.end());
- rectangles.push_back({1000000500, 0});
- int max_width_of_rectangles_with_cur_length = 0;
- int max_width_of_long_rectangles = 0;
- int ans = 0;
- for (int i = n - 1; i >= 0; --i) {
- if (rectangles[i].length != rectangles[i + 1].length) {
- max_width_of_long_rectangles = max(
- max_width_of_long_rectangles,
- max_width_of_rectangles_with_cur_length
- );
- max_width_of_rectangles_with_cur_length = rectangles[i].width;
- }
- if (!(rectangles[i].width < max_width_of_long_rectangles)) {
- ans++;
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement