#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; int main() { int N, X, Y; cin >> N >> X >> Y; int Z = X + Y; vector P(N), C(N); for (int i = 0; i < N; i++) { char c; cin >> P[i] >> c; C[i] = c == 'B'; } vector> profit(Z, vector(2)); for (int i = 0; i < N; i++) profit[i % Z][C[i]] += P[i]; debug(profit); vector> v; for (int i = 0; i < Z; i++) v.push_back(make_pair(profit[i][0] - profit[i][1], i)); sort(v.rbegin(), v.rend()); debug(v); ll ans = 0; for (int i = 0; i < X; i++) { int idx = v[i].second; ans += profit[idx][0]; } for (int i = X; i < Z; i++) { int idx = v[i].second; ans += profit[idx][1]; } cout << ans << endl; }