解题思路:
使用HashMap构造键值对存储
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
Map<Integer, ArrayList<Integer>> map = new HashMap<>();
for (int i = 0; i < 10; i++) {
map.put(i, new ArrayList<Integer>());
}
for (int i = 0; i < n; i++) {
map.get(scan.nextInt()).add(scan.nextInt());
}
int target = n / 10;
int res = 0;
for (int i = 0; i < 10; i++) {
if (map.containsKey(i)) {
Collections.sort(map.get(i));
for (int j = 0; j < map.get(i).size() - target; j++) {
res += map.get(i).get(j);
}
}
}
System.out.print(res);
}
}