#include <bits/stdc++.h>
using namespace std;
const int N = 11111119;
int g[N];
set<int> s;
int main() {
int n;
cin >> n;
while(n--) {
int index, value;
cin >> index >> value;
g[index] += value;
s.insert(index);
}
for (auto t:s) {
cout << t << " " << g[t] << endl;
}
return 0;
}
因为输入的index是升序的,不用考虑排序,只需要往数组对应index添加value就行了。用set记录输入的index顺序保证去重。最后按照顺序输出即可



京公网安备 11010502036488号