Advertisement
Salehisayev

revana

Dec 24th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  6. #define MAXX 1005
  7.  
  8. int n , a , b , c , r , t;
  9.  
  10. int main()
  11. {
  12. cin >> t;
  13. for(int i = 0; i < t; i++){
  14. cin >> a >> b >> c >> r;
  15. int x = c - r;
  16. int y = c + r;
  17. if(a > b)
  18. swap(a , b);
  19. if(a >= x && a >= y){
  20. cout << b - a << endl;
  21. continue;
  22. }
  23. if(b <= x && b <= y){
  24. cout << b - a << endl;
  25. continue;
  26. }
  27. if(a <= x && b >= y){
  28. cout << b - a - 2 * r << endl;
  29. continue;
  30. }
  31. if(a >= x && b <= y){
  32. cout << "0" << endl;
  33. continue;
  34. }
  35. if(a <= x && b <= y){
  36. cout << x - a << endl;
  37. continue;
  38. }
  39. if(a >= x && b >= y){
  40. cout << b - y << endl;
  41. continue;
  42. }
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement