#P7340. Double Ranking in a Rational Function Matrix

    ID: 20538 Type: Default 1000ms 256MiB

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\)).
The ranking in a sequence \(c_1, c_2, \dots, c_n\) is defined as follows: A number \(x\) is the \(k\)-th smallest in the sequence if and only if there are exactly \(\alpha\) numbers \(y\) in the sequence with \(y < x\) and exactly \(\beta\) numbers \(y\) with \(y \le x\), and \(\alpha < k \le \beta\).

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:

  1. The first line contains a single integer \(n\) (the length of each array).
  2. The second line contains \(n\) space-separated integers representing the array \(a\).
  3. The third line contains \(n\) space-separated integers representing the array \(b\).
  4. The fourth line contains \(n\) space-separated integers representing the array \(p\).
  5. The fifth line contains \(n\) space-separated integers representing the array \(q\).
  6. The sixth line contains two space-separated integers \(x\) and \(y\).
All arrays use 1-indexing logically, and you should output indices accordingly.

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