-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB.cpp
More file actions
61 lines (56 loc) · 877 Bytes
/
B.cpp
File metadata and controls
61 lines (56 loc) · 877 Bytes
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int aa[n];
set <int> s;
for(int i=0;i<n;i++)
{
cin>>aa[i];
s.insert(aa[i]);
//cout<<s[i]<<' ';
}
//cout<<s.size();
int x=s.size(),a,b,c;
if(x==1)
cout<<0;
else if(x==2)
{
auto it=s.begin();
a=*it;
it++;
b=*it;
if((b-a)%2==0)
{
cout<<(b-a)/2;
}
else
{
cout<<abs(b-a);
}
}
else if(x==3)
{
auto it=s.begin();
a=*it;
it++;
b=*it;
it++;
c=*it;
if((a+c)%2==0 && (a+c)/2==b)
{
cout<<abs(a-b);
}
else
{
cout<<-1;
}
}
else
{
cout<<-1;
}
return 0;
}