-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBessieSlowsDown.java
More file actions
70 lines (68 loc) · 1.62 KB
/
BessieSlowsDown.java
File metadata and controls
70 lines (68 loc) · 1.62 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
import java.io.*;
import java.util.*;
public class BessieSlowsDown {
static PriorityQueue<Integer> times = new PriorityQueue<Integer>();
static PriorityQueue<Integer> distances = new PriorityQueue<Integer>();
public static void main(String[] args) throws IOException
{
//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedReader br = new BufferedReader(new FileReader("slowdown.in"));
int N = Integer.parseInt(br.readLine());
String[] temp; long n, k; int x;
for (int i = 0; i < N; i++)
{
temp = br.readLine().split(" ");
if (temp[0].charAt(0) == 'T')
times.add(Integer.parseInt(temp[1]));
else
distances.add(Integer.parseInt(temp[1]));
}
double d;
double vi = 1;
double t;
double dist = 0; double time = 0; double dnew, tnew;
while (!times.isEmpty() || !distances.isEmpty())
{
if (distances.isEmpty())
{
t = times.peek();
dist = dist + ((t-time)/vi);
time = t;
times.remove();
vi++;
continue;
}
else if (times.isEmpty())
{
d = distances.peek();
time = time + (vi*(d-dist));
dist = d;
distances.remove();
vi++;
continue;
}
d = distances.peek();
t = times.peek();
if ((t-time) < (d-dist)*vi)
{
dist = dist + ((t-time)/vi);
time = t;
times.remove();
}
else
{
dnew = d;
time = time + (vi*(d-dist));
dist = d;
distances.remove();
}
vi++;
}
time += (1000-dist)*vi;
//System.out.println(Math.round(time));
PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("slowdown.out")));
pw.println(Math.round(time));
pw.close();
br.close();
}
}