-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnect.java
More file actions
43 lines (33 loc) · 1.25 KB
/
Connect.java
File metadata and controls
43 lines (33 loc) · 1.25 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
import java.util.Scanner;
public class Connect {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int stops = sc.nextInt();
int distance = sc.nextInt();
int currentTime = 0;
int currentDistance = 0;
int previous = 0;
for(int i = 0; i < stops; i++)
{
int lightDistance = sc.nextInt();
int red = sc.nextInt();
int green = sc.nextInt();
currentDistance += (lightDistance - previous);
currentTime += (lightDistance - previous);
if(currentTime < red)
{
currentTime += (red - currentTime);
}else{
boolean isGreen = false;
int moded = currentTime % (red + green);
if(moded < red)
{
currentTime += (red - moded);
}
}
previous = lightDistance;
}
currentTime += (distance - currentDistance);
System.out.println(currentTime);
}
}