#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了
点赞 评论

相关推荐

头像
11-07 01:12
重庆大学 Java
精致的小松鼠人狠话不多:签哪了哥
点赞 评论 收藏
分享
牛客722552937号:新锐之星有点坑爹,特别是对男的
点赞 评论 收藏
分享
牛客网
牛客企业服务