#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e9 + 100;
const int N = 1e5;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  ll ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    int j = i + 1;
    while (j < n && s[j] == s[i]) j++;
    ll tmp = 0, sum = 0;
    multiset<int> st;
    for (int z = i; z < j; z++) {
      st.insert(a[z]);
      sum += (ll)a[z];
      if (st.size() > k) {
        int elem = (*st.begin());
        sum -= (ll)(elem);
        st.erase(st.begin());
      }
      tmp = max(tmp, sum);
    }
    ans += tmp;
    i = j - 1;
  }
  cout << ans << endl;
  return 0;
}
