-
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
import java.io.*;
import java.util.*;
public class measurement {
public static void main(String[] args) throws IOException {
// initialize file I/O
BufferedReader br = new BufferedReader(new FileReader("measurement.in"));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("measurement.out")));
// read in all of the notes
int n = Integer.parseInt(br.readLine());
int[] day = new int[n];
String[] cow = new String[n];
int[] change = new int[n];
for(int i = 0; i < n; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
day[i] = Integer.parseInt(st.nextToken());
cow[i] = st.nextToken();
change[i] = Integer.parseInt(st.nextToken());
}
br.close();
// the milk variables track the amount of milk that each cows was last known to produce
int bessieMilk = 7, elsieMilk = 7, mildredMilk = 7;
// the on variables are true if that cow produced the highest amount of milk on the previous day
boolean bessieOn = true, elsieOn = true, mildredOn = true;
int dayAdjust = 0;
for(int currDay = 1; currDay <= 100; currDay++) {
// look through the notes to see if there were any changes on this day
for(int i = 0; i < n; i++) {
if(day[i] == currDay) {
if(cow[i].equals("Bessie")) {
bessieMilk += change[i];
}
if(cow[i].equals("Elsie")) {
elsieMilk += change[i];
}
if(cow[i].equals("Mildred")) {
mildredMilk += change[i];
}
}
}
// compute the highest milk total and see which cows produced the most milk
int highestMilk = Math.max(bessieMilk, Math.max(elsieMilk, mildredMilk));
boolean bessieOnNext = (bessieMilk == highestMilk);
boolean elsieOnNext = elsieMilk == highestMilk;
boolean mildredOnNext = mildredMilk == highestMilk;
if(bessieOn != bessieOnNext || elsieOn != elsieOnNext || mildredOn != mildredOnNext) {
dayAdjust++;
}
bessieOn = bessieOnNext;
elsieOn = elsieOnNext;
mildredOn = mildredOnNext;
}
// print the answer
pw.println(dayAdjust);
pw.close();
}
}