33OJ
登录 注册

#P14218. [ICPC 2024 Kunming I] 金牌

[ICPC 2024 Kunming I] 金牌

Problem Description

What a busy week! This weekend, nn programming contests will be held at the same time.

Each contest will award one gold medal for every kk teams that participate in it. That is, if tt teams participate in a contest, it will award ⌊tk⌋\lfloor \frac{t}{k} \rfloor gold medals, where ⌊x⌋\lfloor x \rfloor is the largest integer not exceeding xx. Currently, the ii-th contest has aia_i teams participating.

Baobao is the coach of a university which has mm teams, and he has not decided which contest each team should participate in. Please help him assign one contest to each team so that the total number of gold medals awarded by all contests is maximized.

Input Format

There are multiple test cases. The first line contains an integer TT (1≤T≤1001 \le T \le 100) denoting the number of test cases. For each test case:

The first line contains two integers nn and kk (1≤n≤1001 \le n \le 100, 1≤k≤1091 \le k \le 10^9), denoting the number of contests and the medal ratio.

The second line contains nn integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (1≤ai≤1091 \le a_i \le 10^9), where aia_i denotes how many teams currently participate in the ii-th contest.

The third line contains one integer mm (1≤m≤1091 \le m \le 10^9), denoting the number of teams you need to assign to contests.

Output Format

For each test case, output one line with one integer denoting the maximum total number of gold medals that all contests can award.

2
3 10
239 141 526
6
2 1
300 100
1000
91
1400

Hint

For the first sample, send 22 teams to the 11-st contest and 44 teams to the 33-rd contest. The total number of gold medals is $\lfloor \frac{239 + 2}{10} \rfloor + \lfloor \frac{141 + 0}{10} \rfloor + \lfloor \frac{526 + 4}{10} \rfloor = 24 + 14 + 53 = 91$.

Translated by QwenWork