#include <bits/stdc++.h>
using namespace std;
long long solve(vector<long long> a, vector<long long> b, long long k) {
  if (a.size() + b.size() < k) return -1;
  long long ans = -1;
  long long suma = 0;
  vector<long long> preb;
  preb.push_back(0);
  for (int i = 0; i < b.size(); i++) {
    long long x = preb[i] + b[i];
    preb.push_back(x);
  }
  for (int i = 1; i <= k; i++) {
    if (a.size() < i) break;
    int j = k - i;
    suma += a[i - 1];
    if (b.size() < j || j <= 0) continue;
    ans = max(ans, preb[j] + suma);
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<long long> r, o, w;
  long long a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    char c;
    cin >> c;
    if (c == 'R')
      r.push_back(a[i]);
    else if (c == 'W')
      w.push_back(a[i]);
    else
      o.push_back(a[i]);
  }
  sort(r.begin(), r.end());
  sort(o.begin(), o.end());
  sort(w.begin(), w.end());
  reverse(r.begin(), r.end());
  reverse(o.begin(), o.end());
  reverse(w.begin(), w.end());
  cout << max(solve(r, o, k), solve(w, o, k)) << "\n";
  return 0;
}
