N checkpoint problem.

Revision en3, by atlasworld, 2019-02-24 00:10:18

You are given n checkpoints in (x , y) plane . you have to choose any two pairs i , j (j can be = i ) such that (xj-xi) + (yj-yi) = k

How to solve it in O(n) time .

N = 1e5 .

xi, yi = -1e9 , 1e9

Any idea.

example :

N = 4

(-2 , 2 ) , (0 , 3) , (1 ,2 ) , (1, 2)

k = 0 .

ans = 10

pairs are (1,1) (2,2) (3,3) (4,4) , (2,3) , (2,4) , (3,2) , (3,4) , (4,2) , (4,3)

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English atlasworld 2019-02-24 00:10:18 8
en2 English atlasworld 2019-02-24 00:09:49 174
en1 English atlasworld 2019-02-24 00:06:40 238 Initial revision (published)