#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  queue<long> dmgs;
  long d;
  for (int i = 0; i < n; i++) {
    cin >> d;
    dmgs.push(d);
  }
  char c;
  char last = -1;
  long long totalDmg = 0;
  priority_queue<long> curr;
  while (n--) {
    cin >> c;
    if (c != last) {
      int s = curr.size() > k ? k : curr.size();
      for (int i = 0; i < s; i++) {
        totalDmg += curr.top();
        curr.pop();
      }
      s = curr.size();
      for (int i = 0; i < s; i++) {
        curr.pop();
      }
    }
    last = c;
    curr.push(dmgs.front());
    dmgs.pop();
  }
  int s = curr.size() > k ? k : curr.size();
  for (int i = 0; i < s; i++) {
    totalDmg += curr.top();
    curr.pop();
  }
  cout << totalDmg;
  return 0;
}
