Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define MAXX 1005
- int n , a , b , c , r , t;
- int main()
- {
- cin >> t;
- for(int i = 0; i < t; i++){
- cin >> a >> b >> c >> r;
- int x = c - r;
- int y = c + r;
- if(a > b)
- swap(a , b);
- if(a >= x && a >= y){
- cout << b - a << endl;
- continue;
- }
- if(b <= x && b <= y){
- cout << b - a << endl;
- continue;
- }
- if(a <= x && b >= y){
- cout << b - a - 2 * r << endl;
- continue;
- }
- if(a >= x && b <= y){
- cout << "0" << endl;
- continue;
- }
- if(a <= x && b <= y){
- cout << x - a << endl;
- continue;
- }
- if(a >= x && b >= y){
- cout << b - y << endl;
- continue;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement