luogu#P4864. Jerry Loves Lines

Jerry Loves Lines

Background

Jerry really likes drawing straight lines on paper.

Problem Description

Jerry has drawn NN lines on paper. Each line can be written as y=kix+biy = k_i x + b_i. Now Jerry wants to know, for each of the MM lines that can be written as X=AjX = A_j, what the yy-coordinate is of the intersection point that ranks KK-th when counted from bottom to top.

If xx lines intersect a line X=AjX = A_j at the same point, it is counted as xx points.

Input Format

The first line contains three positive integers N,M,KN, M, K.

The next NN lines each contain two non-zero integers kik_i and bib_i, describing one line.

The next MM lines each contain one integer AjA_j, representing a query.

Output Format

Output MM lines. Each line contains one integer, representing the answer.

2 3 1
1 2
2 1
0
1
2

1
3
4

Hint

For 30%30\% of the testdata, 1N,M20001 \leqslant N, M \leqslant 2000.
For 100%100\% of the testdata, 1N20001 \leqslant N \leqslant 2000, 1M5×1051 \leqslant M \leqslant 5 \times 10^5.

All other input numbers are within the int range, and it is guaranteed that 1KN1 \leqslant K \leqslant N.

Friendly reminder: if you are not confident about the constant factor of your solution, please inhale oxygen (use O2 optimization). If you are fully confident, go ahead and do whatever you want.

int*int会爆int!!!\color{white}{\text{int*int会爆int!!!}}

Translated by ChatGPT 5