去他妈的NOI难度

从 $S$ 到 byx 的每个人连条容量为生命的边,从手气君的每个人到 $E$ 连条容量为生命的边;如果 byx 的这个人能打赢对方的某个人连一条容量为 $1$ 的边,$+1s$ 的话直接加到生命里,最后跑一遍最大流即可。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// ==============================
// author: memset0
// website: https://memset0.cn
// ==============================
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int read() {
int x = 0; bool m = 0; char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') m = 1, c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
if (m) return -x; else return x;
}

int readc() {
char c = getchar(), t;
while (!isupper(c)) c = getchar();
t = getchar();
while (isupper(t)) t = getchar();
return c;
}

const int maxn = 2010, maxm = 100010;

int n, m, ans, cnt;

struct people {
char kind;
int health;
} a[maxn], b[maxn];

int tot = 2, hed[maxn], nxt[maxm], to[maxm], val[maxm];

void add_edge(int u, int v, int w) {
nxt[tot] = hed[u];
to[tot] = v;
val[tot] = w;
hed[u] = tot++;

nxt[tot] = hed[v];
to[tot] = u;
val[tot] = 0;
hed[v] = tot++;
}

const int inf = 2e9 + 7;
int u, s, e, flag, flow;
int cur[maxn], pre[maxn], dep[maxn], gap[maxn];
#define v (to[i])

int max_flow() {
int ans = 0;
for (int i = 1; i <= e; i++)
cur[i] = hed[i];
u = s, pre[u] = 0, gap[0] = e;

while (dep[u] < e) {

flag = 0;
for (int &i = cur[u]; i; i = nxt[i])
if (val[i] && dep[u] == dep[v] + 1) {
u = v;
pre[v] = i;
flag = 1;
break;
}

if (!flag) {
if (!--gap[dep[u]]) break;
dep[u] = e;
for (int i = hed[u]; i; i = nxt[i])
if (val[i] && dep[v] + 1 < dep[u]) {
dep[u] = dep[v] + 1;
cur[u] = i;
}
++gap[dep[u]];
if (u != s)
u = to[pre[u] ^ 1];
}

if (u == e) {
flow = inf;
for (int i = pre[e]; i; i = pre[to[i ^ 1]])
flow = min(flow, val[i]);
for (int i = pre[e]; i; i = pre[to[i ^ 1]])
val[i] -= flow, val[i ^ 1] += flow;
ans += flow;
u = s;
}

}

return ans;
}

#undef v

int main() {

n = read(), m = read();
for (int i = 1; i <= n; i++)
a[i].kind = readc();
for (int i = 1; i <= n; i++)
b[i].kind = readc();
for (int i = 1; i <= n; i++)
a[i].health = read();
for (int i = 1; i <= n; i++)
b[i].health = read();

cnt = 0;
for (int i = 1; i <= n; i++)
if (a[i].kind == 'Y')
cnt++;
for (int i = 1; i <= n; i++)
if (a[i].kind == 'J')
a[i].health += cnt;

cnt = 0;
for (int i = 1; i <= n; i++)
if (b[i].kind == 'Y')
cnt++;
for (int i = 1; i <= n; i++)
if (b[i].kind == 'J')
b[i].health += cnt;

s = (n << 1) + 1, e = (n + 1) << 1;

for (int i = 1; i <= n; i++)
add_edge(s, i, a[i].health);
for (int i = 1; i <= n; i++)
add_edge(i + n, e, b[i].health);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
#define A (a[i].kind)
#define B (b[j].kind)
if ((A == 'W' && (B == 'E' || B == 'Y')) ||
(A == 'J' && (B == 'H' || B == 'W')) ||
(A == 'E' && (B == 'Y' || B == 'J')) ||
(A == 'Y' && (B == 'H' || B == 'J')) ||
(A == 'H' && (B == 'W' || B == 'E')))
add_edge(i, j + n, 1);
#undef A
#undef B
}

ans = min(max_flow(), m);
printf("%d\n", ans);

return 0;
}