#include <iostream>
#include <map>
#include <unordered_map>

using namespace std;

int main() {
    map<int, int> mp;
    int n;
    cin>>n;
    while(n--)
    {
        int x, y;
        cin>>x>>y;
        mp[x]+=y;
    }
    for(auto it:mp)
    cout<<it.first<<" "<<it.second<<"\n";
}

哈希思路没得说,注意到样例也是按键值升序输出的,所以用map不用unordered_map

#牛客春招刷题训练营#