#P7340. 『MdOI R4』Balance

    ID: 5900 远端评测题 2000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>数学二分Special JudgeO2优化洛谷月赛

『MdOI R4』Balance

Description

You are given integer arrays a,b,p,qa, b, p, q of length nn, and define the function f(i,j)=ai+bjpi+qj(1i,jn)f(i,j)=\dfrac{a_i+b_j}{p_i+q_j}(1\le i,j\le n).

You are also given two integers x,yx, y. You need to find a pair (i,j)(i,j) such that f(i,j)f(i,j) is the xx-th smallest among all f(i,t)(t=1,2,,n)f(i,t)(t=1,2,\cdots,n), and is the yy-th smallest among all f(s,j)(s=1,2,,n)f(s,j)(s=1,2,\cdots,n).

In this problem, we say that a number xx is the kk-th smallest in a sequence c1nc_{1\ldots n} if and only if in cc there are exactly α\alpha numbers yy satisfying y<xy<x, and exactly β\beta numbers yy satisfying yxy\le x, and at the same time α<kβ\alpha<k\le \beta.

If no such (i,j)(i,j) exists, output 0 0.

If there are multiple such (i,j)(i,j), output any one of them.

Since balance issues cannot be clarified in a single question, the problem setter will ask you multiple times.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT indicating the number of test cases. For each test case:

The first line contains three positive integers n,x,yn, x, y.

In the next nn lines, each line contains 44 integers. The ii-th line contains four integers ai,bi,pi,qia_i, b_i, p_i, q_i.

Output Format

Output TT lines. Each line contains two integers, representing the (i,j)(i,j) you found.

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

1 3

Hint

[Sample Explanation #1]

  • f(1,1)=1.2;f(1,2)=1.2;f(1,3)=1.25f(1,1)=1.2;f(1,2)=1.2;f(1,3)=1.25.
  • f(2,1)=2;f(2,2)=2;f(2,3)=216f(2,1)=2;f(2,2)=2;f(2,3)=2\frac{1}{6}.
  • f(3,1)=1;f(3,2)=1;f(3,3)=1f(3,1)=1;f(3,2)=1;f(3,3)=1.

f(1,3)f(1,3) is the 33-rd smallest among f(1,1),f(1,2),f(1,3)f(1,1), f(1,2), f(1,3), and f(1,3)f(1,3) is the 22-nd smallest among f(1,3),f(2,3),f(3,3)f(1,3), f(2,3), f(3,3).

[Constraints]

This problem uses bundled testdata.

Subtask ID n\sum n\le ai,bi,pi,qi\vert a_i\vert ,\vert b_i\vert ,p_i,q_i\le (x,y)=(x,y)= Score
11 5×1035\times 10^3 No special limit No special limit 1010
22 No special limit 33
33 10510^5 No special limit (1,n)(1,n) 3030
44 No special limit 2020
55 No special limit 3030

For 100%100\% of the data, 1x,yn5×1051 \le x,y \le n \le 5 \times 10^5, n5×105\sum n \le 5 \times 10^5, ai,bi109|a_i|,|b_i|\le 10^9, 0<pi,qi1090<p_i,q_i\le 10^9, where n\sum n denotes the sum of nn over all test cases.

[Tips and Help]

The input size of this problem is large, so please choose a faster input method.

Translated by ChatGPT 5