This repository was archived by the owner on Feb 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmilk2.java
More file actions
100 lines (80 loc) · 1.77 KB
/
milk2.java
File metadata and controls
100 lines (80 loc) · 1.77 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
TASK:milk2
ID:johnath6
LANG:JAVA
PROG:milk2
*/
import java.io.*;
import java.util.*;
/**
* @author fath
*
*/
public class milk2 {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
int prevmilk=0;
int prevwait=0;
int maxw,maxm,end;
int prevstop=-1;
int start;
int cachex=15;
int cachey=-15;
int prevs=0;
StringTokenizer st;
BufferedReader f=new BufferedReader(new FileReader("milk2.in"));
PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("milk2.out")));
final int N=Integer.parseInt(f.readLine());
maxm=-25;
int[] xx=new int[N];
int[] yy=new int[N];
for(int i=0;i<N;i++) {
st=new StringTokenizer(f.readLine());
xx[i]=Integer.parseInt(st.nextToken());
yy[i]=Integer.parseInt(st.nextToken());
}
Arrays.sort(xx);
Arrays.sort(yy);
if(N!=1) {
for(int i=0;i<N;i++) {
start=xx[i];
end=yy[i];
System.out.println(start+" "+end);
if(cachex>start&&end>cachey) {
prevwait=0;
}
if(prevstop==-1) {
prevstop=end;
prevs=start;
maxw=end-prevstop;
}else {
maxw=start-prevstop;
if(prevs<start) {
start=prevs;
}
maxm=end-start;
System.out.println(" Total:"+maxm+" "+maxw);
}
prevstop=end;
if(maxm>prevmilk) {
prevmilk=maxm;
}
if(maxw>prevwait) {
prevwait=maxw;
}
maxw=0;
maxm=0;
//System.out.println(rangex+" "+rangey);
}
}else {
prevwait=0;
//st=new StringTokenizer(f.readLine());
prevmilk=-xx[0]+yy[0];
}
out.println(prevmilk+" "+prevwait);
f.close();
out.close();
}
}