#P4479. [BJWC2018] 第k大斜率

[BJWC2018] 第k大斜率

Problem Description

On the 2D Cartesian plane, there are nn distinct points. Any two distinct points determine a line. Among all lines whose slopes are defined, sort them by slope in descending order and find the slope of the kk-th line.

To avoid precision errors, please output the floor of the slope. (For example: ⌊1.5⌋=1\lfloor 1.5 \rfloor = 1, ⌊−1.5⌋=−2\lfloor -1.5 \rfloor = -2.)

Input Format

The first line contains two positive integers nn and kk.
Each of the next nn lines contains two integers xi,yix_i, y_i, the coordinates of a point.

Output Format

Output one line containing an integer: the floor of the kk-th largest slope.

4 1
-1 -1
2 1
3 3
1 4
2

Hint

[Sample Explanation]

The slopes of the lines that meet the requirement are −3,−12,23,1,2,52-3, -\frac{1}{2}, \frac{2}{3}, 1, 2, \frac{5}{2}.

[Constraints]

Let MM be the number of lines whose slopes are defined.

  • For 10%10\% of the testdata, 1≤n≤101 \le n \le 10.
  • For 20%20\% of the testdata, 1≤n≤1001 \le n \le 100, ∣xi∣,∣yi∣≤103|x_i|, |y_i| \le 10^3.
  • For 30%30\% of the testdata, 1≤n≤10001 \le n \le 1000.
  • For 40%40\% of the testdata, 1≤n≤50001 \le n \le 5000.
  • For another 20%20\% of the testdata, k=1k = 1.
  • For another 20%20\% of the testdata, 1≤xi,yi≤1031 \le x_i, y_i \le 10^3.
  • For 100%100\% of the testdata, 1≤n≤1000001 \le n \le 100000, 1≤k≤M1 \le k \le M, ∣xi∣,∣yi∣≤108|x_i|, |y_i| \le 10^8.

Translated by ChatGPT 5