#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base ::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  string s;
  cin >> s;
  priority_queue<long long> pq;
  pq.push(arr[0]);
  long long ans = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1]) {
      pq.push(arr[i]);
    } else {
      for (int j = 0; j < k && pq.size() != 0; j++) {
        ans += pq.top();
        pq.pop();
      }
      while (!pq.empty()) pq.pop();
      pq.push(arr[i]);
    }
  }
  for (int j = 0; j < k && pq.size() != 0; j++) {
    ans += pq.top();
    pq.pop();
  }
  cout << ans << endl;
}
