-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
79 lines (78 loc) · 1.5 KB
/
C.cpp
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
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
long long t,l,r,x,a,b,p,ls,rs;
cin>>t;
while(t--)
{
cin>>l>>r>>x;
cin>>a>>b;
if(a==b)
{
cout<<0<<"\n";
continue;
}
ls=0;
rs=0;
if(abs(a-b)>=x)
{
cout<<1<<"\n";
continue;
}
if(abs(a-l)>=x)
ls++;
else
ls=-1;
if(ls==1)
{
if(abs(l-b)>=x)
{
ls=2;
}
else if(abs(l-r)>=x)
{
ls=2;
if(abs(r-b)>=x)
ls=3;
else
ls=-1;
}
else
ls=-1;
}
if(abs(a-r)>=x)
rs++;
else
rs=-1;
if(rs==1)
{
if(abs(r-b)>=x)
{
rs=2;
}
else if(abs(l-r)>=x)
{
rs=2;
if(abs(l-b)>=x)
rs=3;
else
rs=-1;
}
else
rs=-1;
}
if(ls!=-1 && rs!=-1)
cout<<min(ls,rs)<<"\n";
else if(ls!=-1)
cout<<ls<<"\n";
else if(rs!=-1)
cout<<rs<<"\n";
else
cout<<-1<<"\n";
}
return 0;
}