#P1779. 魔鬼杀手

魔鬼杀手

Description

Each monster has some HP. You can cast spells to reduce a monster’s HP. Each spell has a certain damage, meaning one cast reduces the target’s HP by that amount. A monster is defeated if and only if its HP is less than or equal to 00. Casting a spell consumes mana. Because your mana is limited, you want to defeat all monsters using the minimum total mana. Write a program to accomplish this task.

Input Format

The input is given as follows: NN HP1HP_1 HP2HP_2 \ldots HPNHP_N MM Name1Name_1 MP1MP_1 Target1Target_1 Damage1Damage_1 Name2Name_2 MP2MP_2 Target2Target_2 Damage2Damage_2 \ldots NameMName_M MPMMP_M TargetMTarget_M DamageMDamage_M

NN is the number of monsters (1N1001 \le N \le 100). HPiHP_i is the HP of the ii-th monster (1HPi1051 \le HP_i \le 10^5). MM is the number of available spells (1M1001 \le M \le 100). NamejName_j is the name of the jj-th spell, containing at most 3030 uppercase or lowercase letters. MPjMP_j is the mana cost of that spell (0MPj<1000 \le MP_j < 100). TargetjTarget_j is either Single or All, meaning the spell either targets a single monster (Single) or affects all monsters simultaneously (All). DamagejDamage_j is the amount by which one cast reduces each affected target’s HP (0Damagej<1060 \le Damage_j < 10^6). All numbers are integers. At least one spell has a nonzero DamageDamage value.

Output Format

Output one line containing a single integer, the minimum total mana required.

3
8000 15000 30000
3
Flare 45 Single 8000
Meteor 62 All 6000
Ultimate 80 All 9999
232

Hint

Translated by ChatGPT 5