問題一覧 > 通常問題

No.393 Two Bamboos

レベル : / AI推定難易度 : 1475 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 109
作問者 : horiesiniti / テスター : 37zigen
お気に入りにしたユーザー ProblemId : 1189 / 自分の提出
問題文最終更新日: 2026-06-25 18:14:32
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 144 (順位表) の他の問題:

Problem Statement

You are a bamboo craftsman. You cut bamboo to meet your customers' requests.

You currently have 2 bamboos of integer length.
You also have bamboo length requests from multiple customers. Each customer requests one bamboo of integer length.

You will cut the 2 bamboos into pieces to meet the customers' requests, but you do not know whether you can satisfy everyone.
So you have decided to cut the bamboos so that you can provide bamboo to as many customers as possible.

Given the lengths of the bamboos and the list of customers' requests, write a program that computes the maximum number of customers to whom you can provide bamboo.

Input

$d$
$n_{1_1}$ $n_{2_1}$
$m_1$
$A_{1_1}$ $\dots$ $A_{m1_1}$
$\dots$
$n_{1_d}$ $n_{2_d}$
$m_d$
$A_{1_d}$ $\dots$ $A_{md_d}$

The input consists of multiple datasets.

The number of datasets $d$ is given on the first line. $0 \lt d \le 10$

In one dataset, the lengths of the 2 bamboos

$n_1$ $n_2$ are given on one line. $1 \le n_1 , n_2 \le 100000$

On the next line, the number of customers m is given on one line. $1\le m \le 60$

On the line after that, the bamboo length $a_i$ requested by each customer is given, separated by spaces. $1 \le a_i \le 100000$

This makes up one dataset, and it is repeated $d$ times.
For each dataset, answer the maximum number of customers to whom you can provide bamboo. The answer for the $i$-th dataset is $u_i$.

Output

$u_1$
$\dots$
$u_d$
Print a newline at the end.

Sample

Sample 1
Input
4
15 13
6
4 5 7 9 3 7
10 20
6
5 8 9 6 5 7
20 20
9
5 4 4 4 7 6 11 5 4
3 3
3
7 8 4
Output
5
4
8
0

There are 4 datasets. For the 1st dataset, cuts such as 4 5 3 and 7 7 are possible, so the answer is 5 customers.
For the 2nd dataset, cuts such as 5 5 and 6 7 are possible, so the answer is 4 customers.
For the 3rd dataset, cuts such as 4 5 4 7 and 5 4 4 6 are possible, so the answer is 8 customers.
For the 4th dataset, no customer's request can be met, so the answer is 0 customers.

Sample 2
Input
2
10 14
5
4 3 2 7 8
10 10
3
7 7 5
Output
5
2

There are two datasets. For the first one, by cutting the first bamboo into 2 8 and the 2nd bamboo into 4 3 7, you can meet the requests of all 5 customers. For the 2nd dataset, either 7 and 5 or 7 and 7 will do, but in any case you can meet the requests of 2 customers. Therefore, output 5 for the first dataset and 2 for the 2nd dataset. Print a newline after the output for each dataset.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。