Saleh127

codeforces 1366B.cpp

Jun 11th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. #define Faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  6. #define pi acos(-1)
  7. #define yes printf("YES\n");
  8. #define no printf("NO\n");
  9. int main()
  10. {
  11. Faster
  12. test
  13. {
  14. int left,right,i,j=0,k,l,r,n,m,x;
  15. cin>>n>>x>>m;
  16. left=x;
  17. right=x;
  18. while(m--)
  19. {
  20. cin>>l>>r;
  21. if(max(l,left)<=min(r,right))
  22. {
  23. left=min(l,left);
  24. right=max(r,right);
  25. }
  26. }
  27. cout<<right-left+1<<endl;
  28. }
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment