#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  char s[1000][35];
  int a[101];
  int i, j, k;
  int tmp[1000], flag[1000], l, sum_min, sum_max;
  scanf("%d%d", &n, &m);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  getchar();
  sort(a, a + n);
  for (i = 0; i < m; i++) gets(s[i]);
  for (i = 0; i < m; i++) {
    flag[i] = 0;
    tmp[i] = 1;
  }
  l = -1;
  for (i = 0; i < m; i++) {
    if (flag[i] == 0) {
      ++l;
      for (j = 0; j < m; j++) {
        if (i != j && flag[j] == 0)
          if (!strcmp(s[i], s[j])) {
            flag[i] = 1;
            flag[j] = 1;
            tmp[l]++;
          }
      }
    }
  }
  sort(tmp, tmp + l + 1);
  j = 0;
  sum_min = 0;
  sum_max = 0;
  k = n - 1;
  for (i = l; i >= 0; i--) {
    sum_min += tmp[i] * a[j++];
    sum_max += tmp[i] * a[k--];
  }
  printf("%d %d\n", sum_min, sum_max);
  return 0;
}
