Advertisement
matheus_monteiro

Restaurant Customers

Jun 29th, 2024
656
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n;
  6.     cin >> n;
  7.  
  8.     vector<pair<int, int>> v;
  9.     for(int i = 0; i < n; ++i) {
  10.         int a, b;
  11.         cin >> a >> b;
  12.         v.push_back({a, b});
  13.     }
  14.  
  15.     set<int> S;
  16.     for(auto [a, b] : v) {
  17.         S.insert(a);
  18.         S.insert(b);
  19.     }
  20.  
  21.     map<int, int> mapTo;
  22.     int nextNum = 1;
  23.  
  24.     for(int num : S)
  25.         mapTo[num] = nextNum++;
  26.    
  27.     for(int i = 0; i < n; ++i) {
  28.         v[i].first = mapTo[ v[i].first ];
  29.         v[i].second = mapTo[ v[i].second ];
  30.     }
  31.  
  32.     // ------- solução em baixo
  33.  
  34.     vector<int> cnt(500000);
  35.  
  36.     for(int i = 0; i < n; ++i) {
  37.         cnt[ v[i].first ]++;
  38.         cnt[ v[i].second + 1 ]--;
  39.     }
  40.  
  41.     int ans = 0;
  42.     for(int i = 1; i < cnt.size(); ++i) {
  43.         cnt[i] += cnt[i - 1];
  44.         ans = max(ans, cnt[i]);
  45.     }
  46.  
  47.     cout << ans << '\n';
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement