-
Notifications
You must be signed in to change notification settings - Fork 0
/
B.cpp
48 lines (41 loc) · 808 Bytes
/
B.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
#include<bits/stdc++.h>
#define faster ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
{
faster
int q;
cin>>q;
while(q--)
{
int n,x,k;
cin>>n>>k;
int mx,mn;
for(int i=0; i<n; i++)
{
cin>>x;
if(i==0)
{
mx=x;
mn=x;
}
else
{
if(mx<x)
mx=x;
if(mn>x)
mn=x;
}
}
int z=mx-mn;
if(z>2*k)
cout<<-1<<endl;
else
{
cout<<mn+k<<endl;
}
}
return 0;
}