Advertisement
Nusrat_Ullah

CF 570 Div3 A

Jun 26th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6.     int g,t,y,d,x,maxa,mini;
  7.     ll re;
  8.     scanf("%i",&t);
  9.     while(t--){
  10.         scanf("%i %i",&y,&d);
  11.         maxa=-1e9, mini=1e9;
  12.         for(g=0;g<y;g++){
  13.             scanf("%i",&x);
  14.             if(x>maxa)maxa=x;
  15.             if(x<mini)mini=x;
  16.         }
  17.         re=mini+d;
  18.         if(maxa-d<=re)printf("%I64d\n",re);
  19.         else printf("-1\n");
  20.     }
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement