-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMain.java
29 lines (26 loc) · 839 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package od.HJ8;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
/**
* @author yangyi 2023年08月29日16:09:39
*/
class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
TreeMap<Integer, Integer> tree = new TreeMap<>();
for (int i = 0; i < n; i++) {
int key = in.nextInt();
int value = in.nextInt();
if (tree.containsKey(key)) {
tree.put(key, tree.getOrDefault(key, 0) + value);
} else {
tree.put(key, value);
}
}
for (Map.Entry<Integer, Integer> integerIntegerEntry : tree.entrySet()) {
System.out.println(integerIntegerEntry.getKey() + " " + integerIntegerEntry.getValue());
}
}
}