How I Met Your Mother solution codechef

How I Met Your Mother solution codechef


SOLUTION

Click here

On Valentine’s day, Ted was telling his kids the story of “How I met your mother”. The story goes likes this –

Once upon a time in a far land, I decided to give Robin a blue french horn as a symbol of my eternal love for her but your uncle Barney was the main obstacle in my love story.

My house was present at x=x1x=x1, Robin’s house was at x=x2x=x2 and Barney’s house was at x=x3x=x3 (All houses are present on X-axis). Barney has arranged lasers around his house in a circle of a certain radius RR, i.e. from x=x3x=x3, there are lasers at a distanceRdistance≤R on both sides so that he can save his best bro from being committed in a relationship.

It took me so many days to figure out how to cross the lasers. I want you kids to know how much I struggled. So tell me how much distance I will walk without struggling in the laser.


Input How I Met Your Mother solution codechef

First-line contains the total number of test cases TT. Then the test cases follow.

  • The only line of each test case contains 4 integers –
    • x1x1: Ted’s home coordinate,
    • x2x2: Robin’s home coordinate,
    • x3x3: Barney’s home coordinate, and
    • RR: radius of the lasers

Output How I Met Your Mother solution codechef

For each test case, print one integer – the distance for which Ted will not struggle with lasers.


Constraints How I Met Your Mother solution codechef

1T1051≤T≤105
109x1,x2,x3109−109≤x1,x2,x3≤109
0R1080≤R≤108


Example Input How I Met Your Mother solution codechef

3
-1 2 -2 2
6 1 1 4
-3 -6 -5 2


Example Output

2
1
0


Explanation

In the first test case, x1=1x1=−1x2=2x2=2x3=2x3=−2 and R=2R=2. So the path with lasers will be from x=4x=−4 to x=0x=0. Path without lasers => x=0x=0 to x=2x=2 (2 units).

SOLUTION

Click here


How I Met Your Mother solution codechef The Maths Lock solution codechef Minimum Adjacent Swaps to Reach the Kth Smallest Number Minimum Interval to Include Each Query

Codechef is an platform built to programmers compete against others in the community and to improve their knowledge by facing various challenges. Challenges are categorised on the basis of their difficulty level , if your rating is above 2000 you are in top tier i.e, Division 3 and if your rating is between 2000 and 1600 you will be in tier 2 i.e, Division 3 and if your rating is below that you will be in lowest tier i.e, Division 3. You can improve your rating by successful submission with minimum penalty.

 

CODECHEF 

Also Read : Neenade Naa song lyrics with English Translation

Leave a Comment