B - Gentle Pairs Editorial by CoderAnshu


We have to iterate over all pair of points and check whether their slope lies between \(-1\) and \(1\) (inclusive).

Slope of a line \(=\) \(\left ( \frac{y_2 - y_1}{x_2 - x_1} \right )\)and if the slope lies between \(-1\) and \(1\) , then we have to check only if this \(\left | x_2 - x_1 \right| \ge \left|y_2-y_1 \right| \) satisfies. The total time complexity is \(O(n^{2})\).

Sample Code (C++)

posted:
last update: