-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTowers.java
35 lines (32 loc) · 822 Bytes
/
Towers.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
30
31
32
33
34
35
/* https://codeforces.com/contest/37/problem/A
#sorting #map
two way (use map / plain array)
*/
import java.util.HashMap;
import java.util.Scanner;
public class Towers {
static String calHeightAndLength() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
HashMap<Integer, Integer> map = new HashMap<>();
int height = 1;
int length = 0;
for (int i = 0; i < n; i++) {
int temp = sc.nextInt();
if (!map.containsKey(temp)) {
length += 1;
map.put(temp, 1);
} else {
int val = map.get(temp);
if (val + 1 > height) {
height = val + 1;
}
map.replace(temp, val + 1);
}
}
return height + " " + length;
}
public static void main(String[] args) {
System.out.println(calHeightAndLength());
}
}