#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k;
  cin >> n >> k;
  long long mas[n];
  for (long long i = 0; i < n; i++) {
    cin >> mas[i];
  }
  string s;
  cin >> s;
  long long ans = mas[0], counter = 1;
  multiset<long long> multiset;
  multiset.insert(mas[0]);
  for (long long i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      if (counter == k) {
        if (mas[i] > *multiset.begin()) {
          ans += mas[i] - *multiset.begin();
          multiset.erase(multiset.begin());
          multiset.insert(mas[i]);
        }
      } else {
        ans += mas[i];
        multiset.insert(mas[i]);
        counter++;
      }
    } else {
      counter = 1;
      ans += mas[i];
      multiset.clear();
      multiset.insert(mas[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
