fork download
  1. #include <iostream>
  2. using namespace std;
  3. #define ll long long int
  4. #include <cmath>
  5. int main() {
  6. ll a;
  7. cin>>a;
  8. for(ll i=0;i<a;i++){
  9. ll b,c=0;
  10. cin>>b>>c;ll e=0;
  11. ll d[b]={0};ll max=0;ll min=100000000000;
  12. for(ll j=0;j<b;j++) {cin>>d[j];
  13. if(d[j]>max) max=d[j];
  14. if(d[j]<min) min=d[j];
  15. }
  16. e=abs(max-min);
  17. if(e>(2*c)) cout<<-1<<endl;
  18. else {
  19. cout<<min+c<<endl;
  20. }
  21.  
  22. }
  23.  
  24. // your code goes here
  25. return 0;
  26. }
Success #stdin #stdout 0s 15240KB
stdin
1
5 1
1 2 3 4 5
stdout
-1