Checkpoints Problem

Can anyone help me with this ques.

There are N checkpoints on the xy plane. The coordinates of the ith checkpoint is (xi, yi). Now, you have to count the number of pair of checkpoints which satisfies the equation (xi-xj)+(yi-yj)=S where 1 <= i,j <= N.

Input Format:
The first line of the input contains an integer N the total no. of checkpoints.
Then N lines follow, the ith line contains the two space seperated integer xi and yi respectively representing the ith checkpoint.
The next line contains integer S.

Output Format
In the single line of the output print the count of the no. of pairs of checkpoints which satisfy the above equation.

Constraints:
1 <= N < 5 x 10^5
0 <= |xi|, |yi|, |S| <= 10^9

Sample Input
4
1, 2
-2, 2
1, 2
0, 3
0

Sample Output
10

Explanation
The following are the indexes of the pair of points which satisfy the given equation
(1,1), (1, 3), (1, 4)
(2, 2)
(3, 1), (3, 3), (3, 4)
(4, 1), (4, 3), (4, 4)

Mention problem link and your code

1 Like

You can write xi+yi -(xj+yj)=S.
I got a hint as binary search.
Can you give me problem link so that I can try it

1 Like

https://ide.codingblocks.com/s/58483
Here is the code

1 Like

Thanks a lot for helping me out

1 Like