#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 200010;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long A[MAXN];
vector<long long> vec;
char ch, lst;
void f() {
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  for (int x = 0; x < min(k, (long long)vec.size()); x++) ans += vec[x];
  vec.clear();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 1; i <= n; i++) {
    cin >> ch;
    if (i == 1 || ch == lst)
      vec.push_back(A[i]);
    else {
      f();
      vec.push_back(A[i]);
    }
    lst = ch;
  }
  f();
  cout << ans << '\n';
  return 0;
}
