#P10091. [ROIR 2022] 分数排序 (Day 2)
[ROIR 2022] 分数排序 (Day 2)
Background
Translated from ROIR 2022 D2T2.
Problem Description
There are two sequences and , each consisting of distinct integers. Combine them into fractions of the form , reduce each fraction to simplest form, and then sort them in increasing order.
You are given a number and integers . For each , output the -th smallest fraction among the fractions described above.
Input Format
The first line contains two integers and .
The second line contains distinct integers .
The third line contains distinct integers .
The fourth line contains distinct integers .
Output Format
Output lines. The -th line should output the -th fraction in the increasing order. A fraction should be printed in the format p q, and it must be in simplest form.
4 8
3 4 1 2
2 3 4 5
1 16 2 4 5 6 10 15
1 5
2 1
1 4
2 5
1 2
1 2
4 5
3 2
Hint
In the sample, the initial list of fractions is:
$$\left[ \frac{3}{2}, \frac{3}{3}, \frac{3}{4}, \frac{3}{5}, \frac{4}{2}, \frac{4}{3}, \frac{4}{4}, \frac{4}{5}, \frac{1}{2}, \frac{1}{3}, \frac{1}{4}, \frac{1}{5}, \frac{2}{2}, \frac{2}{3}, \frac{2}{4}, \frac{2}{5} \right],$$After reducing, we get:
$$\left[ \frac{3}{2}, \frac{1}{1}, \frac{3}{4}, \frac{3}{5}, \frac{2}{1}, \frac{4}{3}, \frac{1}{1}, \frac{4}{5}, \frac{1}{2}, \frac{1}{3}, \frac{1}{4}, \frac{1}{5}, \frac{1}{1}, \frac{2}{3}, \frac{1}{2}, \frac{2}{5} \right],$$Finally, after sorting in increasing order, we get:
$$\left[ \frac{1}{5}, \frac{1}{4}, \frac{1}{3}, \frac{2}{5}, \frac{1}{2}, \frac{1}{2}, \frac{3}{5}, \frac{2}{3}, \frac{3}{4}, \frac{4}{5}, \frac{1}{1}, \frac{1}{1}, \frac{1}{1}, \frac{4}{3}, \frac{3}{2}, \frac{2}{1} \right].$$This problem uses bundled testdata.
| Subtask | Score | Special Properties |
|---|---|---|
For of the testdata, , , and (so in fact ), , .
Translated by ChatGPT 5