#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
long long int M = 1000000007;
long long int min(long long int a, long long int b) {
  if (a < b) return a;
  return b;
}
long long int max(long long int a, long long int b) { return (a > b) ? a : b; }
long long int modexpo(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % M;
    a = (a * a) % M;
    b /= 2;
  }
  return res;
}
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> arr(n);
  for (long long int i = 0; i < n; i++) cin >> arr[i];
  ;
  string s;
  cin >> s;
  long long i = 0, j = 0;
  long long ans = 0;
  char prev = '0';
  priority_queue<long long> st;
  while (i < n) {
    if (s[i] != prev) {
      long long t = min(st.size(), k);
      while (t--) {
        ans += st.top();
        st.pop();
      }
      while (!st.empty()) st.pop();
      prev = s[i];
      st.push(arr[i]);
    } else {
      st.push(arr[i]);
    }
    i++;
  }
  long long t = min(st.size(), k);
  while (t--) {
    ans += st.top();
    st.pop();
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
