Advertisement
a53

Intervale_AB

a53
Dec 11th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("intervale.in");
  6. ofstream g("intervale.out");
  7.  
  8. struct intervale{
  9. char c;
  10. int val;
  11.  
  12. bool operator < (const intervale &y) const {
  13. return val < y.val;
  14. }
  15.  
  16. } v[200001];
  17.  
  18. int n, i, maxx, nr, sum, a, b;
  19.  
  20. int main() {
  21.  
  22. f >> n;
  23. for(i = 1; i <= n; i++) {
  24. f >> a >> b;
  25. v[2 * i - 1].val = a, v[2 * i - 1].c = 'a';
  26. v[2 * i].val = b + 1, v[2 * i].c = 'b';
  27. }
  28.  
  29. sort(v + 1, v + 2 * n + 1);
  30.  
  31. i = 1;
  32. while(i <= 2 * n) {
  33. nr = v[i].val;
  34. while(v[i].val == nr && i <= 2 * n) {
  35.  
  36. if(v[i].c == 'a') sum++;
  37. if(v[i].c == 'b') sum--;
  38. i++;
  39. }
  40.  
  41. if(sum > maxx)
  42. maxx = sum;
  43. }
  44.  
  45. g << maxx;
  46. return 0;
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement