#include <bits/stdc++.h>
using namespace std;
long long a[200005];
bool cmp(int x, int y) { return x > y; }
int main() {
  ios::sync_with_stdio(false);
  string s;
  int t;
  vector<int> v;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> s;
  v.push_back(a[0]);
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      v.push_back(a[i]);
    } else {
      sort(v.begin(), v.end(), cmp);
      t = min((int)v.size(), m);
      for (int j = 0; j < t; j++) {
        sum += v[j];
      }
      v.clear();
      v.push_back(a[i]);
    }
  }
  sort(v.begin(), v.end(), cmp);
  t = min((int)v.size(), m);
  for (int i = 0; i < t; i++) {
    sum += v[i];
  }
  v.clear();
  cout << sum << endl;
  return 0;
}
