Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
- int main()
- {
- int q;
- fast();
- cin>>q;
- while(q--)
- {
- int n,k;
- cin>>n>>k;
- int ara[n+1],mn,mx=0;
- for(int i=0;i<n;i++)
- {
- cin>>ara[i];
- if(ara[i]>mx)mx=ara[i];
- if(ara[i]<mn)mn=ara[i];
- if(i==0)mn=ara[i];
- }
- //cout<<mn<<mx<<endl;
- int x=mx-mn;
- if(x%2==0)x=x/2;
- else x=(x/2)+1;
- if(x>k)cout<<"-1"<<endl;
- else
- {
- int ans=max(mn+k,mx-x);
- cout<<ans<<endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement