fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8.  
  9. int N;
  10. cin >> N;
  11. int A1,B1,A2,B2;
  12. cin >> A1;
  13. cin >> B1;
  14. for (int i=0;i<N-1;i++)
  15. {
  16. cin >> A2;
  17. cin >> B2;
  18.  
  19. if (A2>B1)
  20. {
  21. cout<<"NO\n"<<endl;
  22. B1= min(B1,B2);
  23. A1 = max(A2,A1);
  24. return 0;
  25. }
  26. else if (B2<A1)
  27. {
  28. cout<<"NO\n"<<endl;
  29. B1= min(B1,B2);
  30. A1 = max(A2,A1);
  31. return 0;
  32. }
  33.  
  34. else if (A2>B2)
  35. {
  36. cout<<"NO\n"<<endl;
  37. B1= min(B1,B2);
  38. A1 = max(A2,A1);
  39. return 0;
  40. }
  41. A1=A2;
  42. B1=B2;
  43. }
  44.  
  45. cout << "YES\n" << endl;
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 5320KB
stdin
2
1 5
6 7
stdout
NO