Zomato OA-5 2022
Problem Description
Imagine a system where vehicles travel in multiples of 1 kilometer. A vehicle can either remain stationary or travel distances like 2 km, 5 km, or 10 km, but not fractional distances such as 2.5 km or 6.34 km.
In this system, a traffic officer stands at an intersection where four roads meet. Due to city developments, barriers have been placed at specific points on some roads at fixed distances from the intersection.
The system uses a Cartesian coordinate system where each unit represents a kilometer. You are given the coordinates of the intersection, the maximum distance a vehicle can travel north and east from the intersection, and the coordinates of the barriers along the roads. Your task is to determine the total distance (in kilometers) the officer can oversee, considering the restrictions imposed by the barriers.
Input Format:
- The first line contains two integers representing the maximum distance the officer can observe north and east.
- The second line contains two integers representing the coordinates of the intersection.
- The third line contains an integer
k
, denoting the number of barriers. - The next
k
lines contain pairs of integers representing the coordinates of the barriers.
Output Format:
Print a single integer that represents the total distance in kilometers over which the officer can monitor, accounting for the barriers.
Constraints
- 1 <= north distance, east distance <= 10000
- (0, 0) <= coordinates of intersection <= (10000, 10000)
- 1 <= number of barriers <= 1000
- (0, 0) <= coordinates of barriers <= (10000, 10000)
Example
Sample Input:
8 8
4 3
3
1 3 4 6 5 3