#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[200003], b[200003];
long long sum;
bool cmp(int a, int b) { return a > b; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  int t = 0;
  getchar();
  char last = 0;
  for (int i = 1; i <= n; ++i) {
    char now;
    scanf("%c", &now);
    if (now == last)
      b[++t] = a[i];
    else {
      if (t > k) {
        sort(b + 1, b + 1 + t, cmp);
      }
      for (int j = 1; j <= min(k, t); ++j) sum += b[j];
      last = now;
      t = 1;
      b[1] = a[i];
    }
  }
  sort(b + 1, b + 1 + t, cmp);
  for (int j = 1; j <= min(k, t); ++j) sum += b[j];
  cout << sum << endl;
}
