#P6248. 准备战斗,选择你的英雄

准备战斗,选择你的英雄

Description

Currently, the game has 3131 heroes, and each match can send 66 heroes into battle. The number of heroes that can actually be used will be less than 3131. Assume simply that each hero’s contribution to the team can be represented by a positive integer viv_i. The team’s total power equals the sum of all heroes’ contributions. In particular, for mm specific pairs of heroes, if they appear together, the team’s total power increases by xix_i.

Note: Hero combinations can repeat; if they repeat, count them multiple times.

Input Format

The first line contains two integers nn and mm, representing the number of available heroes and the number of specific combinations.
The next nn lines each give the name of the ii-th hero first, then an integer viv_i.
The next mm lines each contain two strings aa, bb, and an integer xix_i, meaning that if heroes aa and bb appear together, the total power increases by xix_i.
Guaranteed: aa and bb are not the same hero.

Output Format

Output one integer, the maximum possible team power.

7 0
Sigma 10
Orisa 10
Mei 10
Reaper 10
Moira 10
Lucio 10
Doomfist 1
60
8 2
Pharah 5
Mercy 5
Reinhardt 10
DVA 10
SOLDIER:76 12
Torbjorn 5
Anna 8
Baptiste 10
Pharah Mercy 20
Anna Pharah 5
75

Hint

Sample 1 Explanation

We should choose the first 66 heroes.


Sample 2 Explanation

We should choose Pharah, Mercy, Reinhardt, DVA, SOLDIER:76, Anna.


Constraints

For 40%40\% of the testdata, m=0m=0.
For 100%100\% of the testdata, 6n306 \le n \le 30, 0m300 \le m \le 30, 1xi,vi1001 \le x_i, v_i \le 100, hero name length 10\le 10, and the character set includes uppercase letters, lowercase letters, digits, and colons (:). Each hero name is unique.

Translated by ChatGPT 5