logo AlgoBeat OnlineJudge
登录 注册

#214250. [SCCPC 2021] Monster Hunter

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Ema is the best carry player in a game. In the game, she needs to eliminate monsters. The -th monster has health points (HP) at the beginning. When a monster is attacked by Ema, its HP is reduced by her attack power. When the HP of a monster is less than or equal to , the monster is eliminated.

To make the game more interesting, the attack power is not a constant number. There is a basic attack sequence , and the damage caused is generated by repeating this sequence. Formally, let be the damage caused by the -th attack, we have

To eliminate the monsters as soon as possible, Ema wants to minimize the number of attacks. Can you tell her the minimum number of attacks required to eliminate all the monsters?

输入格式

There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:

The first line contains an integer () indicating the length of the basic attack sequence.

The second line contains integers () indicating the basic attack sequence.

The third line contains an integer () indicating the number of monsters.

The fourth line contains integers () where indicates the initial HP of the -th monster.

It's guaranteed that neither the sum of nor the sum of of all test cases will exceed .

输出格式

For each test case output one line containing one integer indicating the minimum number of attacks to eliminate all the monsters.

样例

样例输入 1

2
2
3 2
3
2 4 2
5
1 2 3 2 1
2
3 3

样例输出 1

4
3

数据范围与提示

For the first example, the damage sequence is . We can attack monsters 1, 2, 3 and 2 in order to eliminate all the monsters.

For the second example, we can attack monsters 2, 2, 1 in order.