-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathB_Two_Tables.java
More file actions
64 lines (51 loc) · 1.37 KB
/
B_Two_Tables.java
File metadata and controls
64 lines (51 loc) · 1.37 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
import java.util.*;
import java.lang.*;
public class B_Two_Tables{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int W=sc.nextInt(),H=sc.nextInt();
int x1=sc.nextInt(),y1=sc.nextInt(),x2=sc.nextInt(),y2=sc.nextInt();
int w2=sc.nextInt(),h2=sc.nextInt();
int w1=(x2-x1),h1=(y2-y1);
int min=Integer.MAX_VALUE;
boolean flag=true;
if(w1+w2>W && h1+h2>H){
System.out.println(-1);
// min=-1;
flag=false;
}
if(flag && w1+w2<=W){
int index1=w2,index2=W-w2;
if(index1>x1){
min=Math.min(min,index1-x1);
}else{
min=0;
}
if(index2<x2){
min=Math.min(min,x2-index2);
}else{
min=0;
}
}
if(flag && h1+h2<=H){
int index1=h2,index2=H-h2;
if(index1>y1){
min=Math.min(min,index1-y1);
}else{
min=0;
}
if(index2<y2){
min=Math.min(min,y2-index2);
}else{
min=0;
}
}
if(flag){
double ans=(1.000000000)*min;
System.out.println(ans);
}
}
}
}