#P9672. Grid Point Selection by Slope

    ID: 22819 Type: Default 1000ms 256MiB

Grid Point Selection by Slope

Grid Point Selection by Slope

You are given a simple polygon that lies entirely in the first quadrant of the Cartesian plane. In other words, every vertex \((x, y)\) of the polygon satisfies \(x > 0\) and \(y > 0\).

Consider all grid points (points with integer coordinates) that lie inside the polygon or on its boundary. The slope of a point \((x, y)\) is defined as \(\frac{y}{x}\). Your task is to sort all these grid points in increasing order according to their slopes. If two points have the same slope, they should be ordered lexicographically, first by \(x\) and then by \(y\). Finally, output the \(k\)-th grid point in this order (1-indexed).

Note: A point on the boundary of the polygon is considered to be inside the polygon.

inputFormat

The input is given in the following format:

n
x1 y1
x2 y2
...
xn yn
k

Here, \(n\) is the number of vertices of the polygon. Each of the following \(n\) lines contains two positive integers \(x_i\) and \(y_i\) representing a vertex of the polygon in order. The last line contains an integer \(k\), which denotes that you have to output the \(k\)-th grid point (1-indexed) after sorting.

outputFormat

Output two integers \(x\) and \(y\) which represent the \(k\)-th grid point after sorting all grid points (inside or on the boundary of the polygon) by increasing order of slope \(\frac{y}{x}\), and then lexicographically if necessary.

sample

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