Spread the word.

Share the link on social media.

Share
  • Facebook
Have an account? Sign In Now

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

Sorry, you do not have permission to ask a question, 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
  • Shop
    • Internshala Answers
Search
Ask A Question

Mobile menu

Close
Ask A Question
  • Home
  • Questions
  • Blog
    • Computer Science(CSE)
    • NPTEL
    • Startup
  • Shop
    • Internshala Answers
Home/ Questions/Q 20104
Next
In Process

SIKSHAPATH Latest Questions

Pavanagg
  • 0
  • 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
  • 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
  • 352 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    2 Answers

    • Voted
    • Oldest
    • Recent
    1. ADMIN 2
      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

    store ads

    Stats

    • Questions 1k
    • Answers 1k
    • Posts 149
    • Best Answers 89
    • This Free AI Tool Translates Entire Books in Minute !
    • AI News: 🎬 Hollywood’s AI Studios, 🎓 OpenAI’s Latest Gift to Educators, 🚚 Class8 Bags $22M, 🧠 Google Gemini’s Memory Upgrade
    • AI NEWS: Legal Action Against OpenAI, $16M Paid, & Elon Musk’s Praise from Investor 🤖💰📑 | AI Boosts Cloud Seeding for Water Security 🌱💧
    • AI News: 🎬AI Video Tool Scam Exposed🤯, 🛰️ AI-Powered Drones to Ukraine 😱, Google’s $20M AI Push, Sam Altman Joins SF’s Leadership Team
    • AI News: 🤝 Biden Meets Xi on AI Talks, 💡 Xavier Niel’s Advice for Europe, ♻️ Hong Kong’s Smart Bin Revolution, 🚀 AI x Huawei

    Explore

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

    Footer

    SIKSHAPATH

    Helpful Links

    • Contact
    • Disclaimer
    • Privacy Policy Notice
    • TERMS OF USE
    • FAQs
    • Refund/Cancellation Policy
    • Delivery Policy for Sikshapath

    Follow Us

    © 2021-24 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.