-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblist.java
More file actions
61 lines (49 loc) · 1.42 KB
/
blist.java
File metadata and controls
61 lines (49 loc) · 1.42 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
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.*;
public class blist {
public static void main(String[] args) throws IOException
{
BufferedReader f = new BufferedReader(new FileReader("blist.in"));
int cowsNum = Integer.valueOf(f.readLine());
int[] start = new int[1001];
int[] end = new int[1001];
int[] buckets = new int[101];
//initialize arrays
// these arrays: index are the elements, the inputs are the actual times
for (int i = 1; i<cowsNum+1; i++)
{
StringTokenizer input = new StringTokenizer(f.readLine());
start[Integer.valueOf(input.nextToken())] = i;
end[Integer.valueOf(input.nextToken())] = i;
buckets[i] = Integer.valueOf(input.nextToken());
}
int temp = 0;
int max = 0;
for(int i = 1; i<1000; i++)
{
if(start[i] != 0)
{
// add the amount of buckets from cow# (which is the index) resulted from the start array
temp += buckets[start[i]];
}
if(end[i] != 0)
{
// subtract the amount of buckets from cow# (which is the index) resulted from the start array
temp -= buckets[end[i]];
}
if(temp > max)
{
max = temp;
}
}
PrintWriter out = new PrintWriter(new BufferedWriter (new FileWriter("blist.out")));
out.print(max);
out.close();
}
}