2590. Magic Slayer

单点时限: 5.0 sec

内存限制: 256 MB

You are in a fantasy monster-ridden world. You are a slayer fighting against the monsters with magic spells.

The monsters have hit points for each, which represent their vitality. You can decrease their hit points by your magic spells: each spell gives certain points of damage, by which monsters lose their hit points, to either one monster or all monsters in front of you (depending on the spell). Monsters are defeated when their hit points decrease to less than or equal to zero. On the other hand, each spell may consume a certain amount of your magic power. Since your magic power is limited, you want to defeat monsters using the power as little as possible.

Write a program for this purpose.

输入格式

The input is given in the following format:

N

HP1

HP2

HPN

M

Name1 MP1 Target1 Damage1

Name2 MP2 Target2 Damage2

NameM MPM TargetM DamageM

N is the number of monsters in front of you (1 ≤ N ≤ 100); HPi is the hit points of the i-th monster (1 ≤ HPi ≤ 100000); M is the number of available magic spells (1 ≤ M ≤ 100); Namej is the name of the j-th spell, consisting of up to 16 uppercase and lowercase letters; MPj is the amount of magic power consumed by the j-th spell (0 ≤ MPj ≤ 99); Target j is either “Single” or “All”, where these indicate the j-th magic gives damage just to a single monster or to all monsters respectively; Damagej is the amount of damage (per monster in case of “All”) made by the j-th magic (0 ≤ Damagej ≤ 999999).

All the numbers in the input are integers. There is at least one spell that gives non-zero damage to monsters.

输出格式

Print in a line the minimum amount of magic power consumed to defeat all the monsters in the input.

样例

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

2 人解决,11 人已尝试。

3 份提交通过,共有 54 份提交。

9.7 EMB 奖励。

创建: 13 年,12 月前.

修改: 6 年,8 月前.

最后提交: 12 年,8 月前.

来源: Japan

题目标签