CF2194B.Offshores

入门

通过率:0%

时间限制:1.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mark loves money very much, and he keeps most of it in the bank. He stores his money in nn different banks. In the ii-th bank, he has aia_i rubles.

One day, Mark decided to gather all his money in one bank, so he will be transferring money from one bank account to another. All interbank transfers are arranged the same way: he can transfer only xx rubles in one transfer, and considering all fees, yy rubles will be credited to the other account (since banks want to make a profit, it holds that y≤xy \leq x).

It is possible that Mark will not be able to transfer all his money to one bank, but he wants to find the maximum number of rubles that can end up in any bank.

马克非常爱钱,他把大部分钱都存放在银行里。他在 nn 家不同的银行中存有钱,其中在第 ii 家银行中,他有 aia_i 卢布。

一天,马克决定将他所有的钱集中到一家银行中,因此他需要在不同银行账户之间进行转账。所有银行间转账的规则都相同:每次转账只能转出恰好 xx 卢布,且由于手续费等原因,接收方账户实际仅能收到 yy 卢布(由于银行希望盈利,因此满足 y≤xy \leq x)。

马克可能无法将全部钱都转移到同一家银行,但他希望找出最终能集中到某一家银行中的最大卢布数额。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains three integers nn, xx, and yy (2≤n≤2⋅1052 \le n \le 2 \cdot 10^5, 1≤y≤x≤1091 \le y \le x \le 10^9) — the number of banks, the transfer amount, and the credited amount.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \le a_i \le 10^9) — the initial amount of rubles in each bank.

It is guaranteed that the sum of the values of nn across all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、xx 和 yy(2≤n≤2⋅1052 \le n \le 2 \cdot 10^5,1≤y≤x≤1091 \le y \le x \le 10^9)——分别表示银行数量、转账金额和入账金额。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \le a_i \le 10^9)——表示每家银行初始的卢布金额。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single number — the maximum number of rubles that can be obtained in any bank.

对于每个测试用例,输出一个数字——即在任意一家银行中能够获得的卢布最大数量。

输入输出样例

  • 输入#1

    6
    4 5 4
    10 9 8 7
    5 13 11
    47 52 64 13 91
    2 1 1
    1000 1000
    3 15 14
    34 43 52
    6 7 6
    15 17 14 15 12 16
    2 15 10
    45 44

    输出#1

    25
    229
    2000
    113
    72
    74

说明/提示

In the first test case, the optimal sequence of transfers may look as follows: $$ 1\to4,\; 1\to4,\; 4\to3,\; 4\to3,\; 4\to3,\; 3\to2,\; 3\to2,\; 3\to2,\; 3\to2. $$ Let's show the changes in sums after each step: $$ (10,9,8,7) $$ $$ \xrightarrow{1\to4} (5,9,8,11) \xrightarrow{1\to4} (0,9,8,15) $$ $$ \xrightarrow{4\to3} (0,9,12,10) \xrightarrow{4\to3} (0,9,16,5) \xrightarrow{4\to3} (0,9,20,0) $$ $$ \xrightarrow{3\to2} (0,13,15,0) \xrightarrow{3\to2} (0,17,10,0) \xrightarrow{3\to2} (0,21,5,0) \xrightarrow{3\to2} (0,25,0,0). $$

As a result, in one bank (specifically the second one), it is possible to obtain 2525 rubles, and this value is the answer for this test case.

In the third test case, it is possible to transfer one ruble from the first bank to the second bank 10001000 times and obtain 20002000 rubles in the second bank.

在第一个测试用例中,最优的转账序列可能如下所示:

1→4,  1→4,  4→3,  4→3,  4→3,  3→2,  3→2,  3→2,  3→2.1\to4,\; 1\to4,\; 4\to3,\; 4\to3,\; 4\to3,\; 3\to2,\; 3\to2,\; 3\to2,\; 3\to2.

我们展示每一步操作后各银行金额之和的变化:

(10,9,8,7)(10,9,8,7)

→1→4(5,9,8,11)→1→4(0,9,8,15)\xrightarrow{1\to4} (5,9,8,11) \xrightarrow{1\to4} (0,9,8,15)

→4→3(0,9,12,10)→4→3(0,9,16,5)→4→3(0,9,20,0)\xrightarrow{4\to3} (0,9,12,10) \xrightarrow{4\to3} (0,9,16,5) \xrightarrow{4\to3} (0,9,20,0)

→3→2(0,13,15,0)→3→2(0,17,10,0)→3→2(0,21,5,0)→3→2(0,25,0,0).\xrightarrow{3\to2} (0,13,15,0) \xrightarrow{3\to2} (0,17,10,0) \xrightarrow{3\to2} (0,21,5,0) \xrightarrow{3\to2} (0,25,0,0).

最终,在某一家银行(具体为第二家银行)中可获得 2525 卢布,该值即为此测试用例的答案。

在第三个测试用例中,可以将 11 卢布从第一家银行转账至第二家银行共 10001000 次,从而在第二家银行获得 20002000 卢布。

输入解题思路,AI测评打分。不知道怎么写?

首页