#include <bits/stdc++.h>
using namespace std;
int main() {
  int n = 0, m = 0, l = 1;
  long long sum = 0;
  string s = "";
  cin >> n >> m;
  vector<int> buf1(n + 1, 0);
  vector<int> buf2;
  for (int i = 0; i < n; i++) {
    cin >> buf1[i];
  }
  cin >> s;
  s += ' ';
  for (int i = 1; i <= n; i++) {
    if (l == 1) {
      buf2.push_back(buf1[i - 1]);
    }
    if (s[i] == s[i - 1]) {
      buf2.push_back(buf1[i]);
      l++;
    } else {
      sort(buf2.rbegin(), buf2.rend());
      l = min(l, m);
      for (int j = 0; j < l; j++) {
        sum += buf2[j];
      }
      buf2.clear();
      l = 1;
    }
  }
  cout << sum;
}
