fork download
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int num;
  6. int n1,n2;
  7. cin >> num;
  8. int nums[num*2];
  9. int i = 0;
  10. int max = 0;
  11. int min = 0;
  12. int first = 1;
  13. int count = 0;
  14. while(num--)
  15. {
  16. cin >> n1 >> n2;
  17. if(first)
  18. {
  19. min = n1;
  20. max = n2;
  21. first = 0;
  22. }
  23. if(min > max)
  24. count += (min - max) - 1;
  25. if(n2 > max)
  26. max = n2;
  27. if(min > n2)
  28. count += (min - n2) - 1;
  29. if(n1 < min)
  30. min = n1;
  31. }
  32. cout << count;
  33. }
Success #stdin #stdout 0.01s 5320KB
stdin
4
1 3
2 6
8 10
9 12
stdout
Standard output is empty