#P7340. Double Ranking in a Rational Function Matrix
Double Ranking in a Rational Function Matrix
Double Ranking in a Rational Function Matrix
You are given four arrays of integers a, b, p, and q, each of length (n). Define the function (f(i,j)=\frac{a_i+b_j}{p_i+q_j}) for (1 \le i,j \le n).
After the arrays, you are given two integers (x) and (y). Your task is to find a pair ((i,j)) with (1 \le i,j \le n) such that:
- \(f(i,j)\) is the \(x\)-th smallest value in the sequence \(f(i,1), f(i,2), \dots, f(i,n)\) (i.e. in row \(i\)).
- \(f(i,j)\) is the \(y\)-th smallest value in the sequence \(f(1,j), f(2,j), \dots, f(n,j)\) (i.e. in column \(j\)).
If no such pair exists, output “0 0”. If there are multiple answers, output any one of them.
Note: It is guaranteed that \(p_i+q_j\) is non-zero for all valid \(i,j\).
inputFormat
The input consists of multiple lines:
- The first line contains a single integer \(n\) (the length of each array).
- The second line contains \(n\) space-separated integers representing the array \(a\).
- The third line contains \(n\) space-separated integers representing the array \(b\).
- The fourth line contains \(n\) space-separated integers representing the array \(p\).
- The fifth line contains \(n\) space-separated integers representing the array \(q\).
- The sixth line contains two space-separated integers \(x\) and \(y\).
outputFormat
Output two space-separated integers (i) and (j) that satisfy the specified conditions. If no such pair exists, output “0 0”.
sample
2
1 2
3 4
5 6
7 8
1 1
1 1