-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_15702.java
More file actions
67 lines (54 loc) · 2.01 KB
/
Copy pathBOJ_15702.java
File metadata and controls
67 lines (54 loc) · 2.01 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// BOJ - 15702
// Problem Sheet - https://www.acmicpc.net/problem/15702
import java.util.*;
import java.io.*;
import java.util.stream.Collectors;
public class Main {
static class Student implements Comparable<Student> {
private final int number;
private final int score;
public Student(int number, int score) {
this.number = number;
this.score = score;
}
public int getNumber() { return this.number; }
public int getScore() { return this.score; }
@Override
public int compareTo(Student s) {
if (this.score == s.getScore()) {
return this.number - s.getNumber();
}
return s.getScore() - this.score;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] points = Arrays.stream(br.readLine().split(" "))
.mapToInt(Integer::parseInt)
.toArray();
Map<Integer, Integer> scores = new HashMap<>();
for (int i=0 ; i<m ; i++) {
st = new StringTokenizer(br.readLine());
int number = Integer.parseInt(st.nextToken());
for (int j=0 ; j<n ; j++) {
String result = st.nextToken();
scores.put(number, scores.getOrDefault(number, 0) + (result.equals("O") ? points[j] : 0));
}
}
List<Student> students = scores.entrySet()
.stream()
.map(e -> new Student(e.getKey(), e.getValue()))
.sorted()
.collect(Collectors.toList());
System.out.printf(
"%d %d\n",
students.get(0).getNumber(),
students.get(0).getScore()
);
br.close();
System.exit(0);
}
}