#P3701. 主主树

    ID: 2682 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>字符串网络流洛谷原创图的建立,建图最大流

主主树

Description

Soon, the trees blossomed and bore fruit. byx and Shino-chan were surprised to find that theirs were Zhuzhu Trees, full of Zhuzhu and Zhuzhu’s friends. There are five kinds of people on the tree: Zhuzhu (J\verb!J!), Jiji (HK\verb!HK!), Gaogao (W\verb!W!), Wangwang (E\verb!E!), and Waiwai (YYY\verb!YYY!). They found that the numbers of people on their Zhuzhu Trees are the same, both equal to NN.

Research shows that the win–lose relationships among the five kinds are as in the figure above (two people of the same kind cannot “PK”). Arrows point to the loser. As for why, think about it yourself.

The contest begins as scheduled.

byx and Shino-chan will play MM matches. In each match, they will each choose one person from their own tree to see who is stronger.

The ii-th person has a lifetime of Lifei\text{Life}_i seconds. After each match, both participants lose 1s-1\text{s}. When someone’s lifetime reaches 0s0\text{s}, they can no longer play.

Also, when a J\verb!J!’s lifetime is 00, any YYY\verb!YYY! on the same tree can add +1s+1\text{s} to that J\verb!J!. Each YYY\verb!YYY! can extend each J\verb!J! at most once.

The problem:

Given N,M(1N100,1M1000)N, M (1\le N\le 100, 1\le M\le 1000), the kind of each person for Shino-chan and byx (one of $\verb!J!, \verb!HK!, \verb!W!, \verb!YYY!, \verb!E!$), and each person’s lifetime (not exceeding 5050), compute the maximum number of matches that byx can win.

The testdata guarantees that there will be available participants for every match. Any pair of two specific people can play at most one match.

Input Format

The first line contains two integers N,MN, M, as described above.
The second line contains NN strings (J,HK,W,YYY\verb!J!, \verb!HK!, \verb!W!, \verb!YYY! or E\verb!E!), the kinds of byx’s people, separated by spaces.
The third line contains NN strings (J,HK,W,YYY\verb!J!, \verb!HK!, \verb!W!, \verb!YYY! or E\verb!E!), the kinds of Shino-chan’s people, separated by spaces.
The fourth line contains NN integers, the lifetimes of byx’s people.
The fifth line contains NN integers, the lifetimes of Shino-chan’s people.

Output Format

Output a single integer: the number of matches byx can win.

3 3
J W YYY
J HK E
2 2 2
2 2 2

3

Hint

In the first match, J\verb!J! beats HK\verb!HK!. In the second match, W\verb!W! beats E\verb!E!. In the third match, YYY\verb!YYY! beats HK\verb!HK!.

Translated by ChatGPT 5