Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

SIKSHAPATH

SIKSHAPATH Navigation

  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Contact
  • Delivery Policy for Sikshapath
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Contact
  • Delivery Policy for Sikshapath
Home/Questions/Q 20104
Next
In Process
Pavanagg
  • 0
Pavanagg
Asked: August 3, 20222022-08-03T22:47:33+05:30 2022-08-03T22:47:33+05:30In: Other

Chef and Chefina are at positions X and Y on …

  • 0

Chef and Chefina are at positions X and Y on a

number line.

 

They both love badminton.

 

It is known that badminton courts are located at

every integer point.

 

They want to find a court such that the maximum

distance travelled by either of them is minimized.

 

Formally, suppose they choose the badminton court at position Z. You need to find the minimum value of max(| X − Z |, | Y- Z |) across all possible choices of Z. Here, |X| denotes absolute value of X.

Report this minimum value.

 

Input Format

• The first line of input will contain a single integer T,

denoting the number of test cases.

 

• Each test case consists of two space-separated

integers X and Y.

Output Format

For each test case, output the minimum possible

value of max(| X − Z |,| Y − Z |).

 

Constraints

• 1 ≤ T ≤ 1000
• 1 ≤ X, Y ≤ 1000
• X ≠ Y

Sample 1:

Input
4
3 5
7 6
1 10
63 31

Output

1
1
5
16

Explanation:
Test case 1: They will choose the court at position 4 in the optimal case where both have to travel a distance of 1 unit.

Test case 2: They can either choose the court at position 6 or position 7. In both the cases one person has to travel a distance of 1 unit.

  • 2 2 Answers
  • 219 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. ADMIN 2
      2022-08-03T22:49:51+05:30Added an answer on August 3, 2022 at 10:49 pm
      #include <iostream>
      
      
      using namespace std;
      
      
      
      
      int main() {
      
      
      // your code goes here
      
      
      
      
      
      int t;
      
      
      cin>>t;
      
      
      while(t--){
      
      
      int a,b;
      
      
      cin>>a>>b;
      
      
      int k=(a+b)/2;
      
      
      int ma=max(abs(k-a), abs(k-b));
      
      cout<<ma<<endl;
      
      
      }
      return 0;
      }
      • -1
      • Reply
      • Share
        Share
        • Share on WhatsApp
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn

    Leave an answer
    Cancel reply

    You must login to add an answer.

    Forgot Password?

    Need An Account, Sign Up Here

    Sidebar

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 138
    • Best Answers 65
    • NPTEL Solution: Cloud Computing Assignment 2 Answers 2023
    • Solution Revealed: NPTEL Programming in Java Week 1 Assignment 2023
    • NPTEL Joy of Computing Using Python Assignment Answers Week 1 2023
    • NPTEL Cloud Computing Assignment 1 Answers 2023
    • NPTEL An Introduction to Artificial Intelligence Week 1 Assignment Answers 2023

    Popular Questions

    • I'M ADMIN

      Internshala ethical hacking final test answers: Question sequence differs but ...

      • 6 Answers
    • AK

      You have a green lottery ticket, with ints a, b, ...

      • 4 Answers
    • mj

      Solve by Gauss Elimination Method 5x+y+z+w=4 ,x+7y+z+w=12 , x+y+6z+w=-5, x+y+z+4w=-6

      • 3 Answers

    Explore

    • Recent Questions
    • Questions For You
    • Answers With Time
    • Most Visited
    • New Questions
    • Recent Questions With Time

    Footer

    Helpful Links

    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy

    Follow

    © 2021-2022 Sikshapath. All Rights Reserved

    Insert/edit link

    Enter the destination URL

    Or link to existing content

      No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.