#C7331. Minimum Mana Sum

    ID: 51191 Type: Default 1000ms 256MiB

Minimum Mana Sum

Minimum Mana Sum

You are given a collection of magical objects, each with an associated mana value. For each query, your task is to choose k objects such that the sum of their mana values is minimized.

To solve the problem, you should sort the list of mana values and then compute the prefix sums. More formally, if the sorted mana values are \(a_1, a_2, \dots, a_n\), then the answer for a query \(k\) is:

\(S[k] = \sum_{i=1}^{k} a_i\)

There are multiple test cases in the input. For each test case, first you are given the number of magical objects and the number of queries, followed by the list of mana values and the queries. For each query, output the corresponding minimal mana sum.

inputFormat

The input is given from standard input and consists of multiple test cases. The first line contains an integer \(T\), the number of test cases. For each test case:

  • The first line contains two integers \(n\) and \(q\), where \(n\) is the number of magical objects and \(q\) is the number of queries.
  • The second line contains \(n\) integers representing the mana values of the magical objects.
  • The third line contains \(q\) integers representing the queries. For each query, the integer \(k\) indicates that you need the sum of the smallest \(k\) mana values.

outputFormat

For each query in the order they are given (across all test cases), print the minimal possible sum on a new line.

## sample
1
5 3
10 20 30 40 50
1 2 3
10

30 60

</p>