求帮忙看看赛马不过的原因 本地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; }
点赞 评论

相关推荐

祈求顺利毕业😁:简历很好了,多投吧牛油😂。主要是环境不好,大家也卷
点赞 评论 收藏
转发
牛客网
牛客企业服务