#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, k, a[N];
char s[N];
long long ans;
multiset<int> st;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    if (s[i] == s[i - 1]) {
      st.insert(a[i]);
      if (int(st.size()) > k) st.erase(st.find(*st.begin()));
    } else {
      for (auto to : st) ans += to;
      st.clear();
      st.insert(a[i]);
    }
  }
  for (auto to : st) ans += to;
  cout << ans;
  return 0;
}
