#P15766. [JAG 2025 Summer Camp #2] Mix Condiments

[JAG 2025 Summer Camp #2] Mix Condiments

题目描述

You are working in the development department of Incredible Condiment Product Corporation. This company currently sells nn kinds of condiments numbered 11 through nn. The condiment ii has acridity aia_i and sourness sis_i.

A recent market research revealed that consumers desire a new condiment of acridity xx and sourness yy, though none of the nn condiments has such taste. Here, you wonder whether such a condiment can be manufactured by mixing two of the condiments. If two condiments are mixed to create a new one, its acridity and sourness are the weighted means from the two. More precisely, by mixing pp gram of condiment cc and qq gram of condiment dd where pp and qq are any positive real numbers, the acridity and sourness of the new condiment become pac+qadp+q\frac{pa_c + qa_d}{p + q} and psc+qsdp+q\frac{ps_c + qs_d}{p + q}, respectively.

Please find all the possible unordered pairs of condiments such that by mixing those two in some ratio, you can create a condiment of acridity xx and sourness yy.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} & n \\ & a_1 \ s_1 \\ & a_2 \ s_2 \\ & \vdots \\ & a_n \ s_n \\ & x \ y \end{aligned} $$

The first line contains an integer nn (2n502 \leq n \leq 50) representing the number of condiments that your company currently sells. Each of the following nn lines contains two integers aia_i and sis_i (0ai,si500 \leq a_i, s_i \leq 50) representing the acridity and sourness of condiment ii. The last line contains two integers xx and yy (0x,y500 \leq x, y \leq 50) representing the acridity and sourness of the condiment that consumers desire.

It is guaranteed that (ai,si)(x,y)(a_i, s_i) \neq (x, y) for any ii (1in1 \leq i \leq n).

输出格式

Print the answer in the following format.

$$\begin{aligned} & m \\ & c_1 \ d_1 \\ & c_2 \ d_2 \\ & \vdots \\ & c_m \ d_m \end{aligned} $$

mm is the number of all pairs of condiments such that by mixing those two in some ratio, you can create a condiment of acridity xx and sourness yy. cic_i and did_i (1ci<din1 \leq c_i < d_i \leq n) are the numbers of condiments in each pair.

The pairs must be output in the lexicographical order. More precisely, for any ii and jj (1i<jm1 \leq i < j \leq m), either of the following properties must hold.

  • ci<cjc_i < c_j
  • ci=cjc_i = c_j and di<djd_i < d_j
8
8 6
4 8
6 0
10 5
3 7
6 50
7 7
8 6
6 7
5
1 2
2 4
2 8
3 6
5 7
6
10 20
10 30
20 10
30 10
0 0
49 50
10 10
0