Codeforces Round 1081 (Div. 2)
C
All-in-one Gun
Codeforces
1300
原题
← BD →
翻译中…

You are developing a new shooter game, but since there are a lot of shooter games out there, you decide to have something unique in your game.

翻译中…

You have an all-in-one gun that shoots bullets in a fixed order. There are $n$ bullets in the magazine, the $i$-th of which deals $a_i$ damage. The enemy starts with $h$ health and dies when its health becomes $\le 0$.

翻译中…

The gun shoots one bullet per second. After firing all $n$ bullets, it must reload, which takes $k$ seconds. Reloading always restores the same sequence of bullets $[a_1, a_2, \ldots, a_n]$. You cannot reload early; you must empty the magazine first. At the start, the magazine is already full.

翻译中…

Before the fight begins, you may perform at most one swap: pick any indices $1 \le i \lt j \le n$ and exchange $a_i$ with $a_j$.

翻译中…

Your task is to find the minimum number of seconds needed to kill the enemy, taking into account this optional single swap.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each testcase contains three integer $n$, $h$ and $k$ ($2 \le n \le 2\cdot 10^5$, $ 1 \le h, k \le 10^9$) — the size of magazine, health of your enemy and time required to reload the magazine.

翻译中…

The second line of each testcase contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).

翻译中…

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ over all test cases.

翻译中…

Output

翻译中…

For each testcase, output a single integer denoting the minimum time required to kill the enemy.

翻译中…

Note

翻译中…

In the first test case, you swap the bullets present at index $2$ and $5$. This makes array $a$ as $4, 3, 3, 5, 2$.

翻译中…

After $3$ seconds, the health of your enemy will be $10 - 4 - 3 - 3 = 0$, hence the enemy dies in $3$ seconds. It can be shown that achieving time to kill less than $3$ is not possible.

翻译中…

In the third test case, you swap bullets present at index $1$ and $3$. This makes array $a$ as $3, 2, 1$.

翻译中…

In $7$ seconds, you shoot the entire first magazine ($3$ seconds) $+$ reload a new magazine ($2$ seconds) $+$ shoot the first and the second bullet from the new magazine ($2$ seconds).

翻译中…

The health of the enemy will be $10 - 3 - 2 - 1 - 3 - 2 = -1$, hence the enemy dies in $7$ seconds. It can be shown that achieving time to kill less than $7$ is not possible.

翻译中…

样例

Input #1
6
5 10 1
4 2 3 5 3
5 10 1
4 2 3 7 3
3 10 2
1 2 3
2 5 3
2 1
3 18 5
1 2 3
4 10 10
1 1 2 2
Output #1
3
2
7
6
19
17
InputCopy OutputCopy
题目信息
题号
2192C
时间限制
2 s
内存限制
256 MB
标签
二分
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。