求帮忙看看赛马不过的原因 本地OK的 #include<iostream> #include<cmath> #include<iomanip> #include<map> #include<unordered_map> #include<vector> #include<list> #include<string> #include<algorithm> using namespace std; int main() { int m, n; while (cin >> n >> m) { int temp, min_val = 0, max_val = 0;; vector<int>total; string food_input; unordered_map<string, int> food; for (int i = 0; i < n; ++i) { cin >> temp; cin.get(); total.push_back(temp); } sort(total.begin(), total.end()); for (int i = 0; i < m; ++i) { getline(cin, food_input); food[food_input]++; } vector<pair<string, int>> xmliu; for (auto it = food.begin(); it != food.end(); ++it) xmliu.push_back(make_pair(it->first, it->second)); sort(xmliu.begin(), xmliu.end(), [](const pair<string, int> &x, const pair<string, int> &y) -> int { return x.second < y.second;}); int j = 0; for (auto it = xmliu.rbegin(); it != xmliu.rend(); ++it) { min_val += (it->second * total[j]); ++j; } j = total.size() - 1; for (auto it = xmliu.rbegin(); it != xmliu.rend(); ++it) { max_val += (it->second * total[j]); --j; } cout << min_val << " " << max_val << endl; } return 0; }
点赞 评论

相关推荐

无敌虾孝子:喜欢爸爸还是喜欢妈妈
点赞 评论 收藏
分享
贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
牛客网
牛客企业服务