jakaria_hossain

codeforce - Equalize Prices

Jun 26th, 2019
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  4. int main()
  5. {
  6. int q;
  7. fast();
  8. cin>>q;
  9. while(q--)
  10. {
  11. int n,k;
  12. cin>>n>>k;
  13. int ara[n+1],mn,mx=0;
  14. for(int i=0;i<n;i++)
  15. {
  16. cin>>ara[i];
  17. if(ara[i]>mx)mx=ara[i];
  18. if(ara[i]<mn)mn=ara[i];
  19. if(i==0)mn=ara[i];
  20. }
  21. //cout<<mn<<mx<<endl;
  22. int x=mx-mn;
  23. if(x%2==0)x=x/2;
  24. else x=(x/2)+1;
  25. if(x>k)cout<<"-1"<<endl;
  26. else
  27. {
  28. int ans=max(mn+k,mx-x);
  29. cout<<ans<<endl;
  30. }
  31. }
  32. }
RAW Paste Data