Escape from a Rectangle
InterviewTime limit2sMemory limit128 MB
Given a point inside an axis-aligned rectangle, compute the minimum distance from the point to the nearest side of the rectangle.
- Level
Easy1 of 10
- Topics
- Math, Geometry, Implementation
- Solved
- No attempts yet
Problem
Hansoo is at the point (x, y) on the coordinate plane. Each side of the rectangle is parallel to a coordinate axis, with lower-left corner (0, 0) and upper-right corner (w, h). Find the minimum distance Hansoo must move to reach the boundary of the rectangle.
Input
The first line contains four integers x, y, w, and h.
Output
Print the minimum distance from the point to the boundary of the rectangle.
Constraints
- 1 <= w, h <= 1,000
- 1 <= x <= w - 1
- 1 <= y <= h - 1
- x, y, w, and h are integers.