Advertisement
goshansmails

Untitled

Apr 4th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. struct Rectangle{
  8.     int length;
  9.     int width;
  10. };
  11.  
  12. bool operator<(const Rectangle& lhs, const Rectangle& rhs) {
  13.     if (lhs.length == rhs.length) {
  14.         return lhs.width < rhs.width;
  15.     }
  16.     return lhs.length < rhs.length;
  17. }
  18.  
  19. int main() {
  20.     int n;
  21.     cin >> n;
  22.  
  23.     vector<Rectangle> rectangles(n);
  24.     for (int i = 0; i < n; ++i) {
  25.         int length = 0;
  26.         int width = 0;
  27.         cin >> length >> width;
  28.         if (length < width) {
  29.             swap(length, width);
  30.         }
  31.         rectangles[i] = {length, width};
  32.     }
  33.  
  34.     sort(rectangles.begin(), rectangles.end());
  35.     rectangles.push_back({1000000500, 0});
  36.  
  37.     int max_width_of_rectangles_with_cur_length = 0;
  38.     int max_width_of_long_rectangles = 0;
  39.     int ans = 0;
  40.  
  41.     for (int i = n - 1; i >= 0; --i) {
  42.         if (rectangles[i].length != rectangles[i + 1].length) {
  43.             max_width_of_long_rectangles = max(
  44.                     max_width_of_long_rectangles,
  45.                     max_width_of_rectangles_with_cur_length
  46.             );
  47.             max_width_of_rectangles_with_cur_length = rectangles[i].width;
  48.         }
  49.         if (!(rectangles[i].width < max_width_of_long_rectangles)) {
  50.             ans++;
  51.         }
  52.     }
  53.  
  54.     cout << ans << endl;
  55.  
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement