Advertisement
yeskendir_sultanov

Районная олимпиада 2024 - C

Apr 16th, 2025
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | Source Code | 0 0
  1. #include <bits/stdc++.h>
  2. #define L first
  3. #define R second
  4. #define pii pair<int, int>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     int n, m;
  10.     cin >> n >> m;
  11.    
  12.     multiset<int> shirts;
  13.     for (int i = 0; i < n; ++i) {
  14.         int x;
  15.         cin >> x;
  16.         shirts.insert(x);
  17.     }
  18.  
  19.     vector<pii> ranges(m);
  20.     for (int i = 0; i < m; ++i) {
  21.         cin >> ranges[i].L >> ranges[i].R;
  22.     }
  23.     sort(ranges.begin(), ranges.end(), [](auto a, auto b) {
  24.         return (a.R < b.R);
  25.     });
  26.    
  27.     int ans = 0;
  28.     for (auto [l, r] : ranges) {
  29.         auto it = shirts.lower_bound(l);
  30.         if (it != shirts.end() && (*it) <= r) {
  31.             ans++;
  32.             shirts.erase(it);
  33.         }
  34.     }
  35.    
  36.     cout << ans;
  37.     return 0;
  38. }
  39.  
  40.  
  41.  
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement