题库练习 Halve or Subtract
← 上一题 下一题 →

A15852 | Halve or Subtract

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

You have an array of positive integers $a_1, a_2, \ldots, a_n$ , of length $n$ . You are also given a positive integer $b$ .

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

1. Choose some $1 \le i \le n$ , and replace $a_i$ with $\lceil \frac{a_i}{2} \rceil$ . Here, $\lceil x \rceil$ denotes the smallest integer not less than $x$ .
2. Choose some $1 \le i \le n$ , and replace $a_i$ with $\max(a_i - b, 0)$ .

However, you must also follow these rules:

- You can perform at most $k_1$ operations of type 1 in total.
- You can perform at most $k_2$ operations of type 2 in total.
- For all $1 \le i \le n$ , you can perform at most $1$ operation of type 1 on element $a_i$ .
- For all $1 \le i \le n$ , you can perform at most $1$ operation of type 2 on element $a_i$ .

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

输入格式

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

The first line of each test case contains $n$ , $b$ , $k_1$ , and $k_2$ ( $1 \le n \le 5000$ , $1 \le b \le 10^9$ , $0 \le k_1, k_2 \le n$ ).

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ describing the array $a$ ( $1 \le a_i \le 10^9$ ).

It is guaranteed the sum of $n$ over all test cases does not exceed $5000$ .

输出格式

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

输入输出样例

输入 #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
C++ 编辑器
输入
输出