#C5024. Minimum Time to Reach a Point
Minimum Time to Reach a Point
Minimum Time to Reach a Point
You are given a target point \((X, Y)\) on a 2D grid. Starting from the origin \((0,0)\), your goal is to determine the minimum number of seconds required to reach this point.
In one second, you can move one step in any of the 8 possible directions: up, down, left, right, or any of the 4 diagonal moves. This means that from a given point \((x, y)\), you can move to \((x+1, y)\), \((x-1, y)\), \((x, y+1)\), \((x, y-1)\), \((x+1, y+1)\), \((x+1, y-1)\), \((x-1, y+1)\), or \((x-1, y-1)\) in one step.
The minimum time required to reach \((X, Y)\) is exactly \(\max(|X|,|Y|)\) seconds. This is because we can always move diagonally to reduce both \(|X|\) and \(|Y|\) simultaneously until one of them becomes zero, after which we continue along the axis.
inputFormat
The first line of input contains an integer T
representing the number of test cases.
Each of the next T
lines contains two space-separated integers X
and Y
representing the coordinates of the target point.
outputFormat
For each test case, output the minimum number of seconds needed to reach the point \((X, Y)\) from the origin. Each result should be printed on its own line.
## sample3
3 4
-1 -3
5 5
4
3
5
</p>