atlasworld's blog

By atlasworld, history, 5 years ago, In English

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)

  • Vote: I like it
  • -8
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

This is a problem from an ongoing contest on hackerearth