fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int min(int a, int b){
  7. return (a < b) ? a : b;
  8. }
  9.  
  10. int max(int a, int b){
  11. return (a > b) ? a : b;
  12. }
  13.  
  14.  
  15. const int MAXN = 1000001;
  16.  
  17. int main() {
  18. ios::sync_with_stdio(false);
  19. cin.tie(nullptr);
  20.  
  21. int n;
  22. cin >> n;
  23.  
  24. int x, y;
  25. cin >> x >> y;
  26.  
  27. int min_ = x, max_ = y;
  28. int dlugosc = 1, max_dlugosc = 1;
  29.  
  30. for (int i = 1; i < n; ++i) {
  31. cin >> x >> y;
  32.  
  33. int new_min_ = max(min_, x);
  34. int new_max_ = min(max_, y);
  35.  
  36. if (new_min_ <= new_max_) {
  37. ++dlugosc;
  38. min_ = new_min_;
  39. max_ = new_max_;
  40. } else {
  41. dlugosc = 1;
  42. min_ = x;
  43. max_ = y;
  44. }
  45.  
  46. max_dlugosc = max(max_dlugosc, dlugosc);
  47. }
  48.  
  49. cout << max_dlugosc << "\n";
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 5320KB
stdin
6
6 10
1 5
4 8
2 5
6 8
3 5
stdout
3