#P16402. [ECUSTPC 2026 Spring] 烈焰风暴 2

    ID: 18416 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>数学贪心枚举前缀和2026高校校赛

[ECUSTPC 2026 Spring] 烈焰风暴 2

Background

:::epigraph Do you need my help? :::

Problem Description

Nailong is fighting monsters in a turn-based game. He encounters nn monsters, whose health values are h1,h2,,hnh_1, h_2, \dots, h_n.

In each turn, Nailong can choose to cast exactly one of the following skills once:

  • Fireball: Choose one monster, deal xx damage to it, and consume aa mana from Nailong.
  • Flame Storm: Deal yy damage to all monsters, and consume bb mana from Nailong.

When a monster takes damage, its health is reduced by the same amount. If its health is less than or equal to 00, the monster is killed. When all nn monsters are killed, Nailong wins the battle.

Please help Nailong plan his skill usage so that he wins the battle with the minimum mana cost, and output the minimum mana required.

Input Format

There is only one set of testdata in each test.

The first line contains 55 integers $n, x, y, a, b\ (1 \le n, x, y, a, b \le 2 \times 10^6)$, representing the number of monsters, the damage of Fireball and Flame Storm, and the mana costs of these two skills.

The next line contains nn integers h1,h2,,hn (1hi107)h_1, h_2, \dots, h_n\ (1 \le h_i \le 10^7), representing the health of each monster.

Output Format

Output one line containing one integer, representing the minimum mana cost for Nailong to win the battle.

4 10 8 5 7
9 17 23 40
31
5 3 1 2 5
1 2 3 4 10
17

Hint

Sample 1 Explanation

One feasible plan is to use Flame Storm 33 times, and then use Fireball 22 times on the last monster.

Then the other monsters take 8×3=248 \times 3 = 24 damage, and the last monster takes 24+10×2=4424 + 10 \times 2 = 44 damage, so all of them are killed.

The mana cost is 3×7+2×5=313 \times 7 + 2 \times 5 = 31, and it can be proven that this is optimal.

Translated by ChatGPT 5