#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<long long int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  string s;
  cin >> s;
  long long int sum = 0;
  long long int m = v[0];
  vector<long long int> dp(n);
  dp[0] = v[0];
  multiset<long long int> st;
  st.insert(v[0]);
  map<char, long long int> mp;
  mp[s[0]]++;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      st.insert(v[i]);
      mp[s[i]]++;
      if (mp[s[i]] > k) {
        m = *st.begin();
        st.erase(st.find(m));
        dp[i] = dp[i - 1] - m + v[i];
        mp[s[i]] = k;
      } else {
        dp[i] = dp[i - 1] + v[i];
      }
    } else {
      mp[s[i - 1]] = 0;
      mp[s[i]]++;
      st.clear();
      st.insert(v[i]);
      dp[i] = dp[i - 1] + v[i];
    }
  }
  cout << dp[n - 1];
  return 0;
}
