fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. vector < pair<int, int> > point;
  7.  
  8. int main(){
  9. int N,M;
  10. cin >> N;
  11. for (int i=0; i < N; i++){
  12. cin >> M;
  13. for (int j=0;j < M;j++){
  14. int x,y;
  15. cin >> x >> y;
  16. point.push_back( make_pair(x,-1) );
  17. point.push_back( make_pair(y, 1) );
  18. }
  19. }
  20. sort (point.begin(), point.end() );
  21. int open = 0;
  22. int sum = 0;
  23. int prev = 0;
  24. for (auto x : point){
  25. if (open == N)
  26. sum += x.first - prev;
  27. open -= x.second;
  28. if (open == N)
  29. prev = x.first;
  30. }
  31. cout << sum;
  32. }
Success #stdin #stdout 0s 16056KB
stdin
3
1 30 80
2 0 20 50 90
2 750 795 972 982
stdout
Standard output is empty