思路:前缀和,差分,排序
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10e6 + 10;
int n, m;
int b[N];
void insert (int l, int r, int c)
{
b[l] += c;
b[r + 1] -= c;
}
int main()
{
cin >> n >> m;
while (m -- ){
int l, r;
cin >> l >> r;
insert (l, r, 1);
}
for (int i = 1; i <= n; i ++) b[i] = b[i - 1] + b[i];
//sort (b + 1, b + n + 1);
nth_element (b + 1, b + n / 2 + 1, b + n + 1);
cout << b[n / 2 + 1] << endl;
return 0;
}