CF1799F.Halve or Subtract

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have an array of positive integers a1,a2,…,ana_1, a_2, \ldots, a_n, of length nn. You are also given a positive integer bb.

You are allowed to perform the following operations (possibly several) times in any order:

  1. Choose some 1≤i≤n1 \le i \le n, and replace aia_i with ⌈ai2⌉\lceil \frac{a_i}{2} \rceil. Here, ⌈x⌉\lceil x \rceil denotes the smallest integer not less than xx.
  2. Choose some 1≤i≤n1 \le i \le n, and replace aia_i with max⁡(ai−b,0)\max(a_i - b, 0).

However, you must also follow these rules:

  • You can perform at most k1k_1 operations of type 1 in total.
  • You can perform at most k2k_2 operations of type 2 in total.
  • For all 1≤i≤n1 \le i \le n, you can perform at most 11 operation of type 1 on element aia_i.
  • For all 1≤i≤n1 \le i \le n, you can perform at most 11 operation of type 2 on element aia_i.

The cost of an array is the sum of its elements. Find the minimum cost of aa you can achieve by performing these operations.

你有一个长度为 nn 的正整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n,同时给定一个正整数 bb。

你可以任意次(可能零次)以任意顺序执行以下两种操作:

  1. 选择某个下标 1≤i≤n1 \le i \le n,将 aia_i 替换为 ⌈ai2⌉\lceil \frac{a_i}{2} \rceil。其中 ⌈x⌉\lceil x \rceil 表示不小于 xx 的最小整数。
  2. 选择某个下标 1≤i≤n1 \le i \le n,将 aia_i 替换为 max⁡(ai−b,0)\max(a_i - b, 0)。

但你还必须遵守以下限制条件:

  • 总共最多执行 k1k_1 次类型 1 的操作;
  • 总共最多执行 k2k_2 次类型 2 的操作;
  • 对每个下标 1≤i≤n1 \le i \le n,最多对元素 aia_i 执行 1 次 类型 1 的操作;
  • 对每个下标 1≤i≤n1 \le i \le n,最多对元素 aia_i 执行 1 次 类型 2 的操作。

数组的代价定义为其所有元素之和。求通过执行上述操作所能达到的数组 aa 的最小代价。

输入格式

Input consists of multiple test cases. The first line contains a single integer tt, the number of test cases (1≤t≤50001 \le t \le 5000).

The first line of each test case contains nn, bb, k1k_1, and k2k_2 (1≤n≤50001 \le n \le 5000, 1≤b≤1091 \le b \le 10^9, 0≤k1,k2≤n0 \le k_1, k_2 \le n).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n describing the array aa (1≤ai≤1091 \le a_i \le 10^9).

It is guaranteed the sum of nn over all test cases does not exceed 50005000.

输入包含多个测试用例。第一行包含一个整数 tt,表示测试用例的数量(1≤t≤50001 \le t \le 5000)。

每个测试用例的第一行包含四个整数 nn、bb、k1k_1 和 k2k_2(1≤n≤50001 \le n \le 5000,1≤b≤1091 \le b \le 10^9,0≤k1,k2≤n0 \le k_1, k_2 \le n)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n,用于描述数组 aa(1≤ai≤1091 \le a_i \le 10^9)。

保证所有测试用例的 nn 值之和不超过 50005000。

输出格式

For each test case, print the minimum cost of aa you can achieve by performing the operations.

对于每个测试用例,输出通过执行操作所能达到的 aa 的最小成本。

输入输出样例

  • 输入#1

    7
    3 2 1 1
    9 3 5
    2 1 2 0
    1000000000 1
    5 3 1 1
    2 8 3 19 3
    6 9 4 2
    1 2 3 4 5 6
    3 10 3 3
    1 2 3
    5 1 0 0
    999999999 999999999 999999999 999999999 999999999
    5 5 4 3
    5 9 10 7 4

    输出#1

    11
    500000001
    23
    6
    0
    4999999995
    6

说明/提示

In the first test case, you can do the following:

  • Perform operation 2 on element a3a_3. It changes from 55 to 33.
  • Perform operation 1 on element a1a_1. It changes from 99 to 55.

After these operations, the array is a=[5,3,3]a = [5, 3, 3] has a cost 5+3+3=115 + 3 + 3 = 11. We can show that this is the minimum achievable cost.

In the second test case, note that we are not allowed to perform operation 1 more than once on a1a_1. So it is optimal to apply operation 1 once to each a1a_1 and a2a_2. Alternatively we could apply operation 1 only once to a1a_1, since it has no effect on a2a_2.

In the third test case, here is one way to achieve a cost of 2323:

  • Apply operation 1 to a4a_4. It changes from 1919 to 1010.
  • Apply operation 2 to a4a_4. It changes from 1010 to 77.

After these operations, a=[2,8,3,7,3]a = [2, 8, 3, 7, 3]. The cost of aa is 2+8+3+7+3=232 + 8 + 3 + 7 + 3 = 23. We can show that this is the minimum achievable cost.

在第一个测试用例中,你可以执行以下操作:

  • 对元素 a3a_3 执行操作 2。其值由 55 变为 33。
  • 对元素 a1a_1 执行操作 1。其值由 99 变为 55。

执行这些操作后,数组变为 a=[5,3,3]a = [5, 3, 3],其代价为 5+3+3=115 + 3 + 3 = 11。我们可以证明这是可达到的最小代价。

在第二个测试用例中,请注意:我们不允许对 a1a_1 执行超过一次操作 1。因此,最优策略是对 a1a_1 和 a2a_2 各执行一次操作 1。或者,我们也可以仅对 a1a_1 执行一次操作 1,因为该操作对 a2a_2 没有影响。

在第三个测试用例中,以下是一种实现代价 2323 的方法:

  • 对 a4a_4 执行操作 1。其值由 1919 变为 1010。
  • 对 a4a_4 执行操作 2。其值由 1010 变为 77。

执行这些操作后,a=[2,8,3,7,3]a = [2, 8, 3, 7, 3]。数组 aa 的代价为 2+8+3+7+3=232 + 8 + 3 + 7 + 3 = 23。我们可以证明这是可达到的最小代价。

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

首页