Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew 🚀
Contest SolutionsPractice
Practice Sheets
MasterclassesLive 👨🏻‍💻

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
© 2026coding75•crackDSA™•Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021•Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/CodeChef/Starters 207/Tourist
PrevNext
CodeChefCodeChef
2 Star
Starters 207

Tourist

MathArrayGeometry
Loading...
Solve on CodeChef

Problem Statement

Official algorithmic problem description and constraints.

Open on CodeChef

Chef is now a tourist in a foreign land. The land can be modelled as an infinite 2


2-D grid.


Chef is currently at (A,B)


(A,B). There are N


N attractions, the i


i-th attraction at coordinate (Xi,Yi)


(Xi

​,Yi

​).

Chef wants to visit 1


1 attraction, but he does not care which one. Find the minimum distance Chef needs to travel to reach some attraction.

Here, the distance is measured by the Manhattan Metric, where Chef can only travel along parallel to one of the axes. For example, the distance between (0,0)


(0,0) and (1,1)


(1,1) is 2


2.

Input Format

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

  • T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
  • The first line of each test case contains 3

  • 3 integers - N,A

  • N,A and B

  • B.
  • The next N

  • N lines contain 2

  • 2 integers each, the i

  • i-th one being Xi

  • Xi
  • ​ and Yi

  • Yi
  • ​.

Output Format

For each test case, output on a new line the distance to the closest attraction.

Constraints

  • 1≤T≤100

  • 1≤T≤100
  • 1≤N≤100

  • 1≤N≤100
  • 0≤A,B≤100

  • 0≤A,B≤100
  • 0≤Xi,Yi≤100

  • 0≤Xi
  • ​,Yi
  • ​≤100

Sample 1:

Input


Output


3 1 0 0 1 1 5 50 50 50 49 49 50 50 51 51 50 50 50 2 50 50 100 100 0 1
2 0 99

Explanation:

Test Case 1 : Chef can only visit the attraction at (1,1)


(1,1), which is distance 2


2 as mentioned in the statement.

Test Case 2 : Chef is located at the same point as an attraction. Thus, the minimum distance is 0


0

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Starters 207
Previous ProblemNext Problem