#include<vector>
#include<algorithm>
#include<stack>
#include<iostream>
#include<math.h>
#include<map>
#include<string>
using namespace std;
void MinMaxsum(vector<string>material, vector<int>price)
{
sort(price.begin(), price.end());
map<string, int>m;
for (int i = 0; i < material.size(); i++)
{
if (m.find(material[i]) == m.end())
m[material[i]] = 1;
else
m[material[i]]++;
}
vector<int>sorts;
for (map<string, int>::iterator it = m.begin(); it != m.end(); it++)
{
sorts.push_back((it->second));
}
sort(sorts.begin(), sorts.end());
int n = sorts.size();
int min_val = 0;
int max_val = 0;
reverse(sorts.begin(), sorts.end());
for (int i = 0; i < n; i++)
{
min_val += sorts[i] * price[i];
}
reverse(price.begin(), price.end());
for (int i = 0; i < n; i++)
{
max_val += sorts[i] * price[i];
}
cout << min_val << " " << max_val << endl;
}
int main()
{
int n;
while (cin>>n)
{
int m;
vector<int>prices;
cin >> m;
for (int i = 0; i < n; i++)
{
int temp;
cin >> temp;
prices.push_back(temp);
}
vector<string>materials;
for (int i = 0; i < m; i++)
{
string temp;
cin >> temp;
materials.push_back(temp);
}
MinMaxsum(materials, prices);
}
return 0;
}
我这个AC了