输出排序好的Map肯定得是用TreeMap

最重要的是getOrDefault,keySet,get这几个函数会不会用,玛德

import java.util.*;
public class Main{
    public static void main(String[] args) throws Exception{
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        TreeMap<Integer, Integer> map = new TreeMap<>();
        while(scan.hasNextInt()){
            int index = scan.nextInt();
            int value = scan.nextInt();
            map.put(index, map.getOrDefault(index, 0)+value);
        }
        for(Integer i : map.keySet()){
            System.out.println(i+" "+map.get(i));
        }
    }
}