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

相关推荐

面试官很友善,&nbsp;对项目是刨根问底,对项目提出的缺点令人难堪,&nbsp;只能不断道歉。【面试问题】🎯&nbsp;**自我介绍与项目概览**1.&nbsp;请用&nbsp;3-4&nbsp;分钟做一个简洁的自我介绍,突出技术栈与研究方向即可,项目细节稍后展开。🧠&nbsp;**算法与代码能力**2.&nbsp;🔢&nbsp;给定一个整数数组,要求用&nbsp;O(n)&nbsp;时间、O(1)&nbsp;额外空间输出每个位置“除自身外所有元素的乘积”,请阐述思路并现场共享屏幕写出&nbsp;C++&nbsp;代码。3.&nbsp;📈&nbsp;给定一个整数数组,说明如何转化为最长非递减子序列问题,并现场共享屏幕写出&nbsp;C++&nbsp;代码。4.&nbsp;✂️&nbsp;针对最长非递减子序列的代码,请进一步压缩中间数组,真正做到&nbsp;O(1)&nbsp;额外空间。🔍&nbsp;**C/C++&nbsp;语言与内存管理**5.&nbsp;🆚&nbsp;请比较&nbsp;C++&nbsp;的&nbsp;new/delete&nbsp;与&nbsp;C&nbsp;的&nbsp;malloc/free&nbsp;的差异。6.&nbsp;🧩&nbsp;malloc/free&nbsp;的底层实现流程是什么?7.&nbsp;🔎&nbsp;实际项目中如何定位内存泄漏?如果没有&nbsp;Valgrind&nbsp;这类工具,如何实现内存泄漏检测器?8.&nbsp;💥&nbsp;描述一种“栈崩但栈顶代码无异常”的实际场景,并解释其成因与排查思路。🛰&nbsp;**xxx项目深挖**9.&nbsp;🌐&nbsp;概述你在观测平台项目中的角色、系统功能与业务价值。10.&nbsp;🧱&nbsp;画出数据流向图并说明11.&nbsp;⚖️&nbsp;为什么引入&nbsp;Redis&nbsp;Stream&nbsp;作为消息队列?削峰填谷的具体策略与降级方案是什么?如果消费速度持续低于生产速度,如何避免&nbsp;Redis&nbsp;内存爆掉?12.&nbsp;🗂️&nbsp;Redis&nbsp;Stream&nbsp;与&nbsp;List、Pub/Sub&nbsp;在消息队列场景下的优劣对比;ACK&nbsp;机制与消费组在内部是如何实现的?13.&nbsp;🔄&nbsp;如果去掉&nbsp;Redis&nbsp;Stream,&nbsp;直连数据库,你会如何重新设计流量控制与降级逻辑?问有没有看过&nbsp;redis&nbsp;源码?&nbsp;没看过为什么要用消息队列?&nbsp;&nbsp;面试官觉得完全没必要。只能不断道歉。了解过&nbsp;stream&nbsp;的实现吗?&nbsp;&nbsp;没有📁&nbsp;**xxx项目深挖**16.&nbsp;🔧&nbsp;为何不用&nbsp;HTTP/RPC?&nbsp;&nbsp;回答不了,&nbsp;实际上项目只是玩票。17.&nbsp;⏳&nbsp;当前实现中有没有通知机制?18.&nbsp;🌐&nbsp;如果改用&nbsp;RESTful&nbsp;API,用&nbsp;URL&nbsp;路径同样模拟层级结构,不是也可以吗?&nbsp;&nbsp;确实是。玩具项目,&nbsp;和生产实际不太相关。
查看19道真题和解析
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务