fork download
  1. #include<stdio.h>
  2. #include<queue>
  3. #include<algorithm>
  4. using namespace std;
  5. struct xy {
  6. int s, e;
  7. }a[121212];
  8. bool sort_s(xy a, xy b) {
  9. if (a.s != b.s)return a.s < b.s;
  10. return a.e < b.e;
  11. }
  12. int C[121212];
  13. priority_queue<int>Q;
  14. int main() {
  15. int n, m;
  16. int i, j;
  17. scanf("%d%d", &n, &m);
  18. for (i = 0; i < n; i++)scanf("%d", &C[i]);
  19. for (i = 0; i < m; i++)scanf("%d%d", &a[i].s, &a[i].e);
  20. sort(C, C + n);
  21. sort(a, a + m, sort_s);
  22. int now = 0, ans = 0;
  23. for (i = 0; i < n; i++) {
  24. while (now < m&&a[now].s <= C[i])Q.push(-a[now++].e);
  25. while (!Q.empty() && -Q.top() < C[i])Q.pop();
  26. if (!Q.empty())ans++, Q.pop();
  27. }
  28. printf("%d", ans);
  29. return 0;
  30. }
Success #stdin #stdout 0s 4416KB
stdin
5 4
7
8
6
2
9
2 5
4 9
0 3
8 13
stdout
3