#C972. Defeating Monsters with Minimal Actions

    ID: 53844 Type: Default 1000ms 256MiB

Defeating Monsters with Minimal Actions

Defeating Monsters with Minimal Actions

In this problem, you are given a series of test cases. Each test case consists of a set of actions and a set of monsters. Every action has an associated power value, and each monster has a health point value. Your task is to determine the minimum number of actions required to defeat each monster.

For a monster with health (H) and actions with powers (a_1, a_2, \dots, a_n), after sorting the actions in non-increasing order (i.e. (a_1 \ge a_2 \ge \dots \ge a_n)), you need to find the smallest positive integer (k) such that [ a_1 + a_2 + \cdots + a_k \ge H. ] If no such (k) exists, output -1 for that monster.

Input and output are handled via standard I/O.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains an integer (T) representing the number of test cases.
  2. For each test case, the input is given in four lines:
    • The first line contains an integer (n), the number of actions available.
    • The second line contains (n) space-separated integers, representing the power values of these actions.
    • The third line contains an integer (m), the number of monsters.
    • The fourth line contains (m) space-separated integers, representing the health points of the monsters.

outputFormat

For each test case, for every monster, output a single integer indicating the minimum number of actions required to defeat that monster. If it is impossible to defeat a monster with the available actions, output -1. All results for a test case should be printed in one line, space-separated.## sample

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