题解 def func(): n = int(input()) dic = {} while n > 0: List = list(map(int, input().split( ))) if List[0] not in dic.keys(): dic[List[0]] = List[1] else: dic[List[0]] = dic[List[0]] + List[1] n -= 1 dic = sorted(dic.items(), key=lambda x:x[0]) for item in dic: print(item[0], item[1]) if __name__ == __main__: func()