#include <bits/stdc++.h>
typedef struct {
  char nome[33];
  int amount;
} fruta;
fruta frutas[100];
int fruits = 0;
char aux[33];
void insere();
int main() {
  int vet[100], n, m, menor, j, k;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &vet[i]);
  getchar();
  for (int i = 0; i < n - 1; i++) {
    menor = i;
    for (j = i + 1; j < n; j++)
      if (vet[j] < vet[menor]) menor = j;
    j = vet[menor];
    vet[menor] = vet[i];
    vet[i] = j;
  }
  for (int i = 0; i < m; i++) {
    gets(aux);
    insere();
  }
  for (int i = 0; i < fruits - 1; i++) {
    menor = i;
    for (j = i + 1; j < fruits; j++)
      if (frutas[j].amount < frutas[menor].amount) menor = j;
    j = frutas[menor].amount;
    frutas[menor].amount = frutas[i].amount;
    frutas[i].amount = j;
  }
  menor = 0;
  j = 0;
  k = 0;
  int i = 0;
  while (i < m) {
    if (frutas[fruits - 1 - k].amount) {
      menor += vet[k];
      j += vet[n - 1 - k];
      frutas[fruits - 1 - k].amount--;
      i++;
    } else
      k++;
  }
  i = 0;
  k = 0;
  printf("%d %d", menor, j);
  return 0;
}
void insere() {
  for (int i = 0; i < fruits; i++)
    if (!strcmp(aux, frutas[i].nome)) {
      frutas[i].amount++;
      return;
    }
  strcpy(frutas[fruits].nome, aux);
  frutas[fruits].amount = 1;
  fruits++;
}
