fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n, m;
  6. pair<int,int> a[200005], b[200005];
  7.  
  8. int main(){
  9. cin >> n;
  10. int mx1=-1, mn1=1000000009, mx2=-1, mn2=1000000009;
  11. for (int i = 1; i <= n; i++){
  12. cin >> a[i].first >> a[i].second;
  13. if (a[i].first>mx1) mx1 = a[i].first;
  14. if (a[i].second<mn1) mn1 = a[i].second;
  15. // orga[i] = a[i];
  16. }
  17. cin >> m;
  18. for (int i = 1; i <= m; i++){
  19. cin >> b[i].first >> b[i].second;
  20. if (b[i].first>mx2) mx2 = b[i].first;
  21. if (b[i].second<mn2) mn2= b[i].second;
  22. // orgb[i] = b[i];
  23. }
  24. int r1 = mx1-mn2;
  25. int r2 = mx2-mn1;
  26. int mx = max(r1, r2);
  27. if (mx <= 0) cout << 0;
  28. else cout << mx;
  29. return 0;
  30. }
Success #stdin #stdout 0s 19184KB
stdin
3
1 5
2 6
3 7
2
2 4
1 4
stdout
Standard output is empty