-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay54.java
More file actions
60 lines (60 loc) · 1.93 KB
/
Copy pathDay54.java
File metadata and controls
60 lines (60 loc) · 1.93 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
import java.util.*;
public class Day54{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
String strsplit[] = str.split(" ");
int ncon[] = new int[Integer.parseInt(strsplit[0])*2];/*No of contests*/
int hworm[] = new int[Integer.parseInt(strsplit[1])];/*No of home to center wormholes*/
int eworm[] = new int[Integer.parseInt(strsplit[2])];/*No of center to home wormholes*/
int minres = Integer.MAX_VALUE;
int index = 0;
for (int i=0;i<Integer.parseInt(strsplit[0]) ;i++ ) {
String str2 = in.nextLine();
String strsplit2[] = str2.split(" ");
ncon[index++] = Integer.parseInt(strsplit2[0]);
ncon[index++] = Integer.parseInt(strsplit2[1]);
}
for (int i=0;i<hworm.length ;i++ ) {
hworm[i] = in.nextInt();
}
for (int i=0;i<eworm.length ;i++ ) {
eworm[i] = in.nextInt();
}
index = 0;
int min = Integer.MAX_VALUE;
int minindex = 0, minindex2 = 0;
for (int i=0;i<Integer.parseInt(strsplit[0]) ;i++ ) {
min = Integer.MAX_VALUE;
for (int j=0;j<hworm.length ;j++ ) {/*calculate min home wormhole to choose*/
if (Math.abs(hworm[j]-ncon[index])<min) {
min = Math.abs(hworm[j]-ncon[index]);
minindex = j;
}
}
index++;
boolean check = false;
for (int j=0;j<eworm.length ;j++ ) {/*to check if any end wormhole is available or not*/
if (ncon[index]<=eworm[j]) {
check = true;
break;
}
}
if (check) {/*if there are no end wormholes then that contest cannot be taken*/
min = Integer.MAX_VALUE;
for (int j=0;j<eworm.length ;j++ ) {/*calculate min home wormhole to choose*/
if (Math.abs(eworm[j]-ncon[index])<min) {
min = Math.abs(eworm[j]-ncon[index]);
minindex2 = j;
}
}
minres = Math.min(eworm[minindex2]-hworm[minindex]+1, minres);
index++;
}else{
index++;
continue;
}
}
System.out.println(minres);
}
}