-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q2456.java
62 lines (52 loc) · 1.63 KB
/
Q2456.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
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
package olympiad;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Q2456 {
private static class Candidate implements Comparable<Candidate>{
int number;
int score[];
int total;
public Candidate(int number){
this.number = number;
score = new int[4];
total = 0;
}
@Override
public int compareTo(Candidate candidate){
if(total == candidate.total){
if(score[3] == candidate.score[3])
return score[2] - candidate.score[2];
return score[3] - candidate.score[3];
}
return total - candidate.total;
}
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
Candidate candidates[] = new Candidate[3];
int N = Integer.parseInt(br.readLine());
for (int i = 0; i < 3; i++)
candidates[i] = new Candidate(i + 1);
for (int i = 0; i < N; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
for (int j = 0; j < 3; j++) {
int score = Integer.parseInt(st.nextToken());
candidates[j].score[score]++;
candidates[j].total += score;
}
}
Arrays.sort(candidates);
if(candidates[2].compareTo(candidates[1]) == 0)
bw.write("0 " + candidates[2].total + "\n");
else
bw.write(candidates[2].number + " " + candidates[2].total + "\n");
br.close();
bw.close();
}
}