fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. const ll maxn = 1e6 + 2;
  5. int main() {
  6. ios_base::sync_with_stdio(false);
  7. cin.tie(nullptr);
  8.  
  9. ll n, k;
  10. cin >> n >> k;
  11. vector<ll> diff(n + 2, 0);
  12.  
  13. while(k--)
  14. {
  15. ll a, b;
  16. cin >> a >> b;
  17. diff[a]++;
  18. diff[b + 1]--;
  19. }
  20.  
  21. for(ll i = 1 ; i <= n ; i++){
  22. diff[i] += diff[i - 1];
  23. }
  24. diff.pop_back();
  25. sort(diff.begin(), diff.end());
  26. cout << diff[(n + 2) / 2] << endl;
  27.  
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5320KB
stdin
7 4
5 5
2 4
4 6
3 5
stdout
1