题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <functional> #include <iostream> #include <queue> #include <unordered_map> #include <vector> using namespace std; using LL = long long; int main() { int n; while (cin >> n) { unordered_map<LL, LL> cnts; priority_queue<LL, vector<LL>, greater<>> index; int a, b; for (int i = 0; i < n; ++i) { cin >> a >> b; if (cnts.find(a) == cnts.end()) { index.push(a); } cnts[a] += b; } while (!index.empty()) { LL k = index.top(); index.pop(); printf("%lld %lld\n", k, cnts[k]); } } } // 64 位输出请用 printf("%lld")