1 2 3 4 5
-----------
1 | 0 0 0 0 0
2 | 0 0 1 0 0
3 | 0 0 0 0 0
4 | 1 0 0 0 0
5 | 0 0 0 0 0
with two points: (x1, y1) = (2, 3) and (x2, y2) = (4, 1).
The fastest way to find out whether these two points share the same diagonal is the result of this expression:
bool result = (x1 + y1 == x2 + y2) or (x1 - y1 == x2 - y2)
Now let's complicate the task. Given matrix n x n with m points, find the minimum number of diagonals which contain at least two points. The first line of the input contains: n m. The next m lines contain points with coordinates (xi, yi).