Task DescriptionDiscussion (0)
Task :: Menhetn
You are given a set of points {(x1, y1), (x2, y2), ..., (xn, yn)}. You should compute the smallest menhetn distance between all the pairs of the points.
Menhetn distance between two points (a, b) and (c, d) is defined as |a - c| + |b - d|.
Menhetn distance between two points (a, b) and (c, d) is defined as |a - c| + |b - d|.
INPUT:
In the first line of the standard input is given an integer n (2 <= n <= 1000). In the next n lines are given the points -- in the i-th is given the point (xi, yi) (-100000 <= xi, yi <= 100000), where both xi and yi are integers.
In the first line of the standard input is given an integer n (2 <= n <= 1000). In the next n lines are given the points -- in the i-th is given the point (xi, yi) (-100000 <= xi, yi <= 100000), where both xi and yi are integers.
OUTPUT:
In the first and the only line of the standard output you should print the smallest distance.
In the first and the only line of the standard output you should print the smallest distance.
Input:
Output:
Explanation:
The distance between the first and the second point is 3 (|1 - 4| + |2 - 2| = 3), as well as the distance between the third and the forth point (|8 - 9| + |3 - 5| = 3).
5
1 2
4 2
8 3
9 5
15 11
1 2
4 2
8 3
9 5
15 11
Output:
3
Explanation:
The distance between the first and the second point is 3 (|1 - 4| + |2 - 2| = 3), as well as the distance between the third and the forth point (|8 - 9| + |3 - 5| = 3).
Input:
Output:
2
-1 1
-1 1
-1 1
-1 1
Output:
0
Submit Solution
Available Languages
Task info
| Name: | Menhetn |
| Time: | 0.1 sec. |
| Memory: | 16 MB |
| #Tests: | 11 |
| AddedBy: | boba5551 |
Task Ratings
| Difficulty: | 2.1 (16 votes) |
| Quality: | 4.2 (13 votes) |
Acceptance Rate
Recent Submissions
Fastest Solutions
| User | Time |
|---|---|
| bl4ck.c0d3r | 0 s. |
| doctore | 0 s. |
| danilo06 | 0 s. |
| Uros94KG | 0.015 s. |
| ervin90 | 0.015 s. |
| LethalFAIL | 0.015 s. |
| Mihajlo94 | 0.015 s. |
| ascii_nikola | 0.015 s. |
| Aleksandar_sd | 0.015 s. |
| kole95 | 0.015 s. |
Solved By
Home
Training
Competitions
Forum
FAQ