#include <bits/stdc++.h>
using namespace std;
void fastio() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
int main() {
  fastio();
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
  }
  string str;
  cin >> str;
  str += "0";
  int len = 1;
  multiset<int> s;
  for (int i = 0; i < n + 1; i++) {
    if (str[i] == str[i + 1]) {
      len++;
      s.insert(v[i]);
    } else {
      s.insert(v[i]);
      if (s.size() > k) {
        while (s.size() != k) {
          sum -= *(s.begin());
          s.erase(s.begin());
        }
      }
      s.clear();
      len = 1;
    }
  }
  cout << sum;
  return 0;
}
