-
Notifications
You must be signed in to change notification settings - Fork 3
/
CCC10S1.java
86 lines (85 loc) · 3.05 KB
/
CCC10S1.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
/**
* CCC '10 S1 - Computer Purchase
* Question type: Simple Math
* 9/9 on DMOJ
* @author Tommy Pang
*/
public class CCC10S1 {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st;
static List<Integer> first = new ArrayList<>(), second = new ArrayList<>();
static Map<Integer, String> name = new HashMap<>();
static Map<String, Integer> price = new HashMap<>();
public static void main(String[] args) throws IOException{
int N = Integer.parseInt(br.readLine());
if (N==1) {
st = new StringTokenizer(br.readLine());
System.out.println(st.nextToken());
return;
}
for (int i = 1; i <= N; i++) {
st = new StringTokenizer(br.readLine());
String s = st.nextToken();
int R = Integer.parseInt(st.nextToken());
int S = Integer.parseInt(st.nextToken());
int D = Integer.parseInt(st.nextToken());
name.put(i, s);
price.put(s, 2*R + 3*S + D);
}
int max = 0;
for (int i = 1; i <= N; i++) {
max = Math.max(price.get(name.get(i)), max);
}
for (int i = 1; i <= N; i++) {
if (price.get(name.get(i))==max) first.add(i);
}
int max2 = 0;
for (int i = 1; i <= N; i++) {
if (price.get(name.get(i))==max) continue;
max2 = Math.max(max2, price.get(name.get(i)));
}
for (int i = 1; i <= N; i++) {
if (price.get(name.get(i))==max2) second.add(i);
}
if (first.size()==1) {
System.out.println(name.get(first.get(0)));
if (second.size() == 1) {
System.out.println(name.get(second.get(0)));
}
else {
String ans = "";
int c = 1000000;
for (Integer integer : second) {
if (name.get(integer).charAt(0) - 'A' < c) {
ans = name.get(integer);
c = name.get(integer).charAt(0) - 'A';
}
}
System.out.println(ans);
}
}
else {
String ans1 = "";
int c = 1000000;
for (Integer integer : first) {
if (name.get(integer).charAt(0) - 'A' < c) {
ans1 = name.get(integer);
c = name.get(integer).charAt(0) - 'A';
}
}
System.out.println(ans1);
c = 1000000;
String ans2 = "";
for (int nxt : first) {
if (!name.get(nxt).equals(ans1) && name.get(nxt).charAt(0) - 'A' < c) {
ans2 = name.get(nxt); c = name.get(nxt).charAt(0) - 'A';
}
}
System.out.println(ans2);
}
}
}