QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 1024 MB Points totaux : 100

#9679. Boxes

Statistiques

There are $n$ boxes numbered $1$ to $n$, where the $i$-th box initially contains $a_i$ balls.

You can perform the following two types of operations:

  • Choose a box and remove one ball from it. The cost is 1.
  • Choose $m$ consecutive boxes and remove a total of at most $k$ balls from them. The cost is $c$.

Find the minimum cost required to remove all balls.

Each test case contains $T$ datasets.

Input

The first line contains an integer $T$.

For each dataset:

The first line contains four integers $n, m, k, c$.

The second line contains $n$ integers $a_1, \dots, a_n$.

Output

For each dataset:

A single integer representing the answer.

Examples

Input 1

3
5 2 4 3
2 2 1 2 2
4 2 4 3
2 4 1 1
10 3 5 1
2 2 2 2 1 1 1 10 2 2

Output 1

7
7
6

Subtasks

For $100\%$ of the data, $1 \le T \le 5 \times 10^5$, $\sum n \le 5 \times 10^5$, $1 \le m \le n$, $1 \le c \le k \le 10^9$, $1 \le a_i \le 10^9$.

Subtask 1 ($17\%$): $n, a_i \le 100$, $\sum n \le 500$.

Subtask 2 ($21\%$): $\sum n \le 500$.

Subtask 3 ($24\%$): $\sum n \le 5 \times 10^3$.

Subtask 4 ($11\%$): $c = 1$.

Subtask 5 ($27\%$): No additional constraints.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.